Skip to content

Commit 9f7eb87

Browse files
committed
only use perl for determining absolute path when "realpath" utility is not installed
1 parent c292d5b commit 9f7eb87

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

app/uninstall.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ if [ $# == 0 ]; then
44
exit 3
55
fi
66

7+
realpath() {
8+
if [ -x "$( which realpath )" ]
9+
then
10+
# call the realpath utility if installed
11+
"$( which realpath )" "$1"
12+
else
13+
# on MacOS there is no realpath utility on a default installation
14+
# -> use fallback to perl
15+
perl -e 'use Cwd "abs_path"; print abs_path(shift)' "$1"
16+
fi
17+
}
18+
719
APP_DIR=$(pwd)
820

921
if [[ -f "$APP_DIR/.bash_cli" ]]; then

bash-cli.inc.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ COLOR_LIGHT_GRAY="\033[37m"
1212
COLOR_DARK_GRAY="\033[38m"
1313
COLOR_NORMAL="\033[39m"
1414

15+
realpath() {
16+
if [ -x "$( which realpath )" ]
17+
then
18+
# call the realpath utility if installed
19+
"$( which realpath )" "$1"
20+
else
21+
# on MacOS there is no realpath utility on a default installation
22+
# -> use fallback to perl
23+
perl -e 'use Cwd "abs_path"; print abs_path(shift)' "$1"
24+
fi
25+
}
26+
1527
function bcli_resolve_path() {
1628
realpath "$1"
1729
}

cli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
#!/usr/bin/env bash
22

3+
realpath() {
4+
if [ -x "$( which realpath )" ]
5+
then
6+
# call the realpath utility if installed
7+
"$( which realpath )" "$1"
8+
else
9+
# on MacOS there is no realpath utility on a default installation
10+
# -> use fallback to perl
11+
perl -e 'use Cwd "abs_path"; print abs_path(shift)' "$1"
12+
fi
13+
}
14+
315
ROOT_DIR=$(dirname "$(realpath "$0")")
416

517
# shellcheck source=./bash-cli.inc.sh

complete

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
#!/usr/bin/env bash
22

3+
# this file is sourced by /etc/bash_completion.d/* and therefore should not shadow
4+
# any existing commands in the shell -> add bcli_ prefix to realpath-helper function here
5+
bcli_realpath() {
6+
if [ -x "$( which realpath )" ]
7+
then
8+
# call the realpath utility if installed
9+
"$( which realpath )" "$1"
10+
else
11+
# on MacOS there is no realpath utility on a default installation
12+
# -> use fallback to perl
13+
perl -e 'use Cwd "abs_path"; print abs_path(shift)' "$1"
14+
fi
15+
}
316

417
function _bash_cli() {
518
local root_dir;
6-
root_dir=$(dirname "$(realpath "$(which "${COMP_WORDS[0]}")")")
19+
root_dir=$(dirname "$(bcli_realpath "$(which "${COMP_WORDS[0]}")")")
720

821
# shellcheck source=./bash-cli.inc.sh
922
. "$root_dir/bash-cli.inc.sh"

help

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
#!/usr/bin/env bash
22

3+
realpath() {
4+
if [ -x "$( which realpath )" ]
5+
then
6+
# call the realpath utility if installed
7+
"$( which realpath )" "$1"
8+
else
9+
# on MacOS there is no realpath utility on a default installation
10+
# -> use fallback to perl
11+
perl -e 'use Cwd "abs_path"; print abs_path(shift)' "$1"
12+
fi
13+
}
14+
315
ROOT_DIR=$(dirname "$(realpath "$0")")
416

517
# shellcheck source=./bash-cli.inc.sh

0 commit comments

Comments
 (0)