-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomCD.sh
More file actions
34 lines (31 loc) · 773 Bytes
/
Copy pathCustomCD.sh
File metadata and controls
34 lines (31 loc) · 773 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
#!/bin/bash
#custom cd-------
function cd(){
local processid="$BASHPID"
local update=true
local tty=`ps h -p $$ -o tty`
if [ "$tty" = '?' ]; then
update=false
else
local processname=`ps h -o args -p "$processid"`
local level=`ps hf -o args,pid |
sed -r -n "/ +$processid$/p" |
sed -r "s/ +$processid//" |
sed -e "s;$processname;;" |
echo -n "\`cat -\`" |
wc --chars |
echo "\`cat -\` / 4" |
bc`
[ ! "$level" = 0 ] && update=false
fi
if [ ! "$OLDPWD" ] && [ "$1" = "-" ]; then
OLDPWD=`cat ~/.cd`
fi
local destination="$1"
[ ! "$destination" ] && destination="$HOME"
builtin cd "$destination" &&
if "$update"; then
# 最後の終了コードはできるだけ0にするためifで評価(winscpの仕様)
pwd > ~/.cd
fi
}