-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zprofile
54 lines (49 loc) · 1.37 KB
/
.zprofile
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
54
look_for_cmd=0
#Prints currently running command
print_cmd() {
if [ ${look_for_cmd} = 1 ] ;then
if [ "${BASH_COMMAND}" != 'print_host' ] ;then
curhist='%h'
cmdline=($(fc -l -n ${(%)curhist}))
#For some commands, we want to know what the first argument is
if [[ "${cmdline}" =~ ^(sudo|ssh|vi|vim|man|more|less)\ ]] ;then
first=$(echo "${cmdline}" | awk '{print $1}')
for i in ${cmdline} ;do
if ! [[ "${i}" =~ ^-.*$ ]] && ! [[ "${i}" =~ ^${first}$ ]] ;then
cmd="${first}[${i}]"
break
fi
done
#Skip a variable assignment
elif [[ "${cmdline}" =~ ^[A-Z]*=.*$ ]] ;then
cmd=$(echo ${cmdline} | awk '{print $2}')
#For "normal" commands, just output the command
else
cmd=$(echo ${cmdline} | awk '{print $1}')
fi
echo ${cmd}
look_for_cmd=0
else
return
fi
fi
}
#Different terminals use different characters to controll the title
case $TERM in
xterm*)
precmd() { print -Pn "\e]0;%n@%m:%~\a" 1>&2 }
preexec() {
look_for_cmd=1
cmd=`print_cmd`
print -Pn "\e]0;%n@%m:${cmd}\a" 1>&2
}
;;
screen*|tmux*)
precmd() { print -Pn "\033k%~\033\\" 1>&2 }
preexec() {
look_for_cmd=1
cmd=`print_cmd`
print -Pn "\033k${cmd}\033\\" 1>&2
}
;;
esac