Skip to content

Commit 6e0a506

Browse files
committed
Refactor clipboard quoting function and update iTerm/tmux title bar handling in .zshrc
1 parent 7d262c5 commit 6e0a506

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

.zshrc

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ clip () {
615615
[ -t 0 ] && pbpaste || pbcopy
616616
}
617617

618-
quote-clipboard() {
618+
quote_clipboard() {
619619
local content=$(pbpaste)
620620

621621
# Check if content already starts with "> "
@@ -773,14 +773,27 @@ setopt notify
773773

774774
# PROMPT AWESOMENESS {{{1
775775

776-
# Since we're setting precmd here, we might also add our hook that updates the
777-
# iTerm title bar with the current directory.
778776
if [ "$TERM_PROGRAM" = "iTerm.app" ]; then
779-
_terminal-precmd() {
780-
echo -ne "\033]0;${PWD##*/}\007"
777+
# Update the iTerm title bar with the current command and reset it to the
778+
# current directory when the command is done.
779+
preexec() {
780+
echo -ne "\033]0;$1\007"
781+
}
782+
_terminal_precmd() {
783+
echo -ne "\033]0;$(basename "$PWD")\007"
784+
}
785+
elif [ -n "$TMUX" ]; then
786+
# Update the tmux title bar with the current command and reset it to the
787+
# current directory when the command is done.
788+
preexec() {
789+
printf '\033]2;%s\033\\' "$1"
790+
}
791+
_terminal_precmd() {
792+
printf '\033]2;%s\033\\' "$(basename "$PWD")"
781793
}
782794
else
783-
_terminal-precmd() {}
795+
preexec() {}
796+
_terminal_precmd() {}
784797
fi
785798

786799
# Turn on prompt substitution.
@@ -844,7 +857,7 @@ colorprompt() {
844857

845858
bindkey "^L" clear-screen-and-precmd
846859
precmd() {
847-
_terminal-precmd
860+
_terminal_precmd
848861
print -P $__first_prompt_line
849862
}
850863
PS1=${(j::)line2}
@@ -862,7 +875,7 @@ uncolorprompt() {
862875
)
863876
bindkey "^L" clear-screen
864877
precmd() {
865-
_terminal-precmd
878+
_terminal_precmd
866879
}
867880
PS1=${(j::)temp}
868881
}
@@ -878,7 +891,7 @@ shortprompt() {
878891
__prompt_mode=${__prompt_mode:-0}
879892
bindkey "^L" clear-screen
880893
precmd() {
881-
_terminal-precmd
894+
_terminal_precmd
882895
echo
883896
}
884897
PS1="%{[${__prompt_mode}m%}$%{%} "
@@ -891,7 +904,7 @@ simpleprompt() {
891904
bindkey "^L" clear-screen
892905
unfunction precmd &>/dev/null
893906
precmd() {
894-
_terminal-precmd
907+
_terminal_precmd
895908
echo
896909
}
897910
PS1="$ "

0 commit comments

Comments
 (0)