-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpath.sh
More file actions
43 lines (32 loc) · 754 Bytes
/
gpath.sh
File metadata and controls
43 lines (32 loc) · 754 Bytes
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
#!/bin/sh
help(){
echo "Usage: $(basename "$0") [DIR] [OPTIONS]
Open another copy of the current terminal emulator.
DIR Directory to open the new terminal in
-h,--help Show this message and exit
-k,--kill Kill the original terminal
"
exit
}
dir="$PWD"
while [ $# -gt 0 ]; do
case $1 in
-k|--kill)
kill=1
shift
;;
-h|--help)
help
;;
*)
dir=$1
shift
;;
esac
done
tpid="$(ps -o ppid= $PPID | tr -d ' ')" # Terminal PID
tcmd="$(ps -p "$tpid" -o command=)" # terminal command
set +m
cmd="sh -c cd $dir;$tcmd"
eval nohup "$cmd" 1>/dev/null 2>/dev/null </dev/null &
[ -n "$kill" ] && kill "$tpid" || :