Skip to content

Commit 924fb8e

Browse files
authored
fix running in an env without which (#101)
* fix running in an env without `which` * use command -v * don't get fancy
1 parent 5c5e095 commit 924fb8e

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,10 @@ jobs:
181181
- uses: actions/checkout@v3
182182
- run: ./install.sh
183183
- run: test $(~/.tea/tea.xyz/v0/bin/tea --prefix) = $HOME/.tea
184+
185+
run-without-which:
186+
runs-on: ubuntu-latest
187+
container: archlinux:latest
188+
steps:
189+
- uses: actions/checkout@v3
190+
- run: ./install.sh

install.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ prepare() {
88
# ensure ⌃C works
99
trap "echo; exit" INT
1010

11-
if ! which tar >/dev/null 2>&1; then
11+
if ! command -v tar >/dev/null 2>&1; then
1212
echo "tea: error: sorry. pls install tar :(" >&2
1313
fi
1414

@@ -54,12 +54,12 @@ prepare() {
5454
fi
5555

5656
if test $ZZ = 'gz'; then
57-
if which base64 >/dev/null 2>&1; then
57+
if command -v base64 >/dev/null 2>&1; then
5858
BASE64_TARXZ="/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AX/AFNdADMb7AG6cMNAaNMVK8FvZMaza8QKKTQY6wZ3kG/F814lHE9ruhkFO5DAG7XNamN7JMHavgmbbLacr72NaAzgGUXOstqUaGb6kbp7jrkF+3aQT12CAAB8Uikc1gG8RwABb4AMAAAAeGbHwbHEZ/sCAAAAAARZWg=="
5959
if echo "$BASE64_TARXZ" | base64 -d | tar Jtf - >/dev/null 2>&1; then
6060
ZZ=xz
6161
fi
62-
elif which uudecode >/dev/null 2>&1; then
62+
elif command -v uudecode >/dev/null 2>&1; then
6363
TMPFILE=$(mktemp)
6464
cat >"$TMPFILE" <<-EOF
6565
begin 644 foo.tar.xz
@@ -94,7 +94,7 @@ prepare() {
9494

9595
if test -z "$TEA_PREFIX"; then
9696
# use existing installation if found
97-
if which tea >/dev/null 2>&1; then
97+
if command -v tea >/dev/null 2>&1; then
9898
set +e
9999
TEA_PREFIX="$(tea --prefix --silent)"
100100
if test $? -eq 0 -a -n "$TEA_PREFIX"; then
@@ -116,7 +116,7 @@ prepare() {
116116
fi
117117

118118
if test -z "$CURL"; then
119-
if which curl >/dev/null 2>&1; then
119+
if command -v curl >/dev/null 2>&1; then
120120
CURL="curl -Ssf"
121121
elif test -f "$TEA_PREFIX/curl.se/v*/bin/curl"; then
122122
CURL="$TEA_PREFIX/curl.se/v*/bin/curl -Ssf"
@@ -150,8 +150,8 @@ gum_no_tty() {
150150
get_gum() {
151151
if test ! -t 1 -o "$GUM" = "0"; then
152152
GUM=gum_no_tty
153-
elif which gum >/dev/null 2>&1; then
154-
GUM=$(which gum)
153+
elif command -v gum >/dev/null 2>&1; then
154+
GUM=gum
155155
elif test -n "$ALREADY_INSTALLED"; then
156156
GUM="tea --silent +charm.sh/gum gum"
157157
elif test -f "$TEA_PREFIX/charm.sh/gum/v0.8.0/bin/gum"; then
@@ -289,7 +289,7 @@ check_path() {
289289
then
290290
mkdir -p /usr/local/bin
291291
ln -sf "$tea" /usr/local/bin/tea
292-
elif which sudo >/dev/null 2>&1
292+
elif command -v sudo >/dev/null 2>&1
293293
then
294294
sudo --reset-timestamp
295295
sudo mkdir -p /usr/local/bin
@@ -302,7 +302,7 @@ check_path() {
302302
EOMD
303303
fi
304304

305-
if ! which tea >/dev/null 2>&1
305+
if ! command -v tea >/dev/null 2>&1
306306
then
307307
echo #spacer
308308
gum_func format -- <<-EOMD
@@ -319,9 +319,9 @@ check_path() {
319319
check_shell_magic() {
320320
# foo knows I cannot tell you why $SHELL may be unset
321321
if test -z "$SHELL"; then
322-
if which finger >/dev/null 2>&1; then
322+
if command -v finger >/dev/null 2>&1; then
323323
SHELL="$(finger "$USER" | grep Shell | cut -d: -f3 | tr -d ' ')"
324-
elif which getent >/dev/null 2>&1; then
324+
elif command -v getent >/dev/null 2>&1; then
325325
SHELL="$(basename "$(getent passwd "$USER")")"
326326
fi
327327
if test -z "$SHELL"; then
@@ -412,7 +412,7 @@ fi
412412

413413
if ! test -d "$TEA_PREFIX/tea.xyz/var/pantry"; then
414414
title="prefetching"
415-
elif which git >/dev/null 2>&1; then
415+
elif command -v git >/dev/null 2>&1; then
416416
title="syncing"
417417
fi
418418
gum_func spin --title "$title pantry" -- "$tea" --sync --dump

0 commit comments

Comments
 (0)