-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpid
executable file
·53 lines (46 loc) · 1.75 KB
/
pid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# dont use a shebang otherwise the shell detection won't work
platform="unknown"
unamestr=$(uname)
if [ "$unamestr" = "Linux" ]; then
platform="linux"
elif [ "$unamestr" = "FreeBSD" ]; then
platform="freebsd"
elif [ "$unamestr" = "Darwin" ]; then
platform="macos"
else
platform="linux"
fi
source_dir=`dirname "$0"`
if [ "$platform" = "macos" ]; then
script_abs_path=$(greadlink -m $source_dir/pid)
ws_dir=$(greadlink -m $script_abs_path/..)
elif [ "$platform" = "freebsd" ]; then
script_abs_path=$(greadlink -m $source_dir/pid)
ws_dir=$(greadlink -m $script_abs_path/..)
else
script_abs_path=$(readlink -m $source_dir/pid)
ws_dir=$(readlink -m $script_abs_path/..)
fi
# Try to make embedded shell detection (e.g bash in zsh) works in all cases
shell_exe_name=$(ps -o fname --no-headers $$) # should always give bash on bash
shell_base_name=$(basename $SHELL) # should always give zsh if the current or parent shell is zsh
if [ "$shell_exe_name" = "bash" ]; then
shell="bash"
else
shell="$shell_base_name"
fi
echo "----------------------------------------------------- WARNING --------------------------------------------------"
echo "Consider sourcing the share/pid.sh script inside your workspace and use the pid command for better shell support"
echo ""
echo "For the current session only run"
echo " source $ws_dir/share/pid.sh"
echo ""
if [ ! -z "$shell" ]; then
echo "Then add the above line to your shell setup script"
echo " echo \"source $ws_dir/share/pid.sh\" >> $HOME/.${shell}rc"
else
echo "Then add this same command to your shell setup script to make it permanent"
fi
echo "----------------------------------------------------------------------------------------------------------------"
. $ws_dir/share/pid.sh
pid $@