diff options
Diffstat (limited to 'zsh')
| -rw-r--r-- | zsh/zshrc | 149 |
1 files changed, 74 insertions, 75 deletions
@@ -49,7 +49,7 @@ alias cp="cp -i" alias gitpush="git add . && git commit --amend --no-edit && git push -f" alias yu="ssh-add -e /usr/lib/x86_64-linux-gnu/libykcs11.so; ssh-add -s /usr/lib/x86_64-linux-gnu/libykcs11.so" alias n="nvim" -alias n.="nvim ." +alias nv="nvim ." alias cp="cp -i" alias df="df -h" alias free="free -m" @@ -104,14 +104,84 @@ WORDCHARS=${WORDCHARS//\/[&.;]} autoload -U compinit colors zcalc compinit -d +# Runs before showing the prompt +function mzc_termsupport_precmd { + [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return + title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE +} + +# Runs before executing the command +function mzc_termsupport_preexec { + [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return + + emulate -L zsh + + # split command into array of arguments + local -a cmdargs + cmdargs=("${(z)2}") + # if running fg, extract the command from the job description + if [[ "${cmdargs[1]}" = fg ]]; then + # get the job id from the first argument passed to the fg command + local job_id jobspec="${cmdargs[2]#%}" + # logic based on jobs arguments: + # http://zsh.sourceforge.net/Doc/Release/Jobs-_0026-Signals.html#Jobs + # https://www.zsh.org/mla/users/2007/msg00704.html + case "$jobspec" in + <->) # %number argument: + # use the same <number> passed as an argument + job_id=${jobspec} ;; + ""|%|+) # empty, %% or %+ argument: + # use the current job, which appears with a + in $jobstates: + # suspended:+:5071=suspended (tty output) + job_id=${(k)jobstates[(r)*:+:*]} ;; + -) # %- argument: + # use the previous job, which appears with a - in $jobstates: + # suspended:-:6493=suspended (signal) + job_id=${(k)jobstates[(r)*:-:*]} ;; + [?]*) # %?string argument: + # use $jobtexts to match for a job whose command *contains* <string> + job_id=${(k)jobtexts[(r)*${(Q)jobspec}*]} ;; + *) # %string argument: + # use $jobtexts to match for a job whose command *starts with* <string> + job_id=${(k)jobtexts[(r)${(Q)jobspec}*]} ;; + esac + + # override preexec function arguments with job command + if [[ -n "${jobtexts[$job_id]}" ]]; then + 1="${jobtexts[$job_id]}" + 2="${jobtexts[$job_id]}" + fi + fi + + # cmd name only, or if this is sudo or ssh, the next cmd + local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%} + local LINE="${2:gs/%/%%}" + + title '$CMD' '%100>...>$LINE%<<' +} + +# Emits the control sequence to notify many terminal emulators +# of the cwd +# +# Identifies the directory using a file: URI scheme, including +# the host name to disambiguate local vs. remote paths. +function mzc_termsupport_cwd { + # Percent-encode the host and path names. + local URL_HOST URL_PATH + URL_HOST="$(zsh_urlencode -P $HOST)" || return 1 + URL_PATH="$(zsh_urlencode -P $PWD)" || return 1 + + # common control sequence (OSC 7) to set current host and path + printf "\e]7;%s\a" "file://${URL_HOST}${URL_PATH}" +} autoload -U add-zsh-hook -#add-zsh-hook precmd mzc_termsupport_precmd -#add-zsh-hook preexec mzc_termsupport_preexec +add-zsh-hook precmd mzc_termsupport_precmd +add-zsh-hook preexec mzc_termsupport_preexec # Use a precmd hook instead of a chpwd hook to avoid contaminating output # i.e. when a script or function changes directory without `cd -q`, chpwd # will be called the output may be swallowed by the script or function. -#add-zsh-hook precmd mzc_termsupport_cwd +add-zsh-hook precmd mzc_termsupport_cwd source ~/.config/zsh/conf.d/*.zsh @@ -223,62 +293,6 @@ function title { ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD ZSH_THEME_TERM_TITLE_IDLE="%n@%m:%~" -# Runs before showing the prompt -function mzc_termsupport_precmd { - [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return - title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE -} - -# Runs before executing the command -function mzc_termsupport_preexec { - [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return - - emulate -L zsh - - # split command into array of arguments - local -a cmdargs - cmdargs=("${(z)2}") - # if running fg, extract the command from the job description - if [[ "${cmdargs[1]}" = fg ]]; then - # get the job id from the first argument passed to the fg command - local job_id jobspec="${cmdargs[2]#%}" - # logic based on jobs arguments: - # http://zsh.sourceforge.net/Doc/Release/Jobs-_0026-Signals.html#Jobs - # https://www.zsh.org/mla/users/2007/msg00704.html - case "$jobspec" in - <->) # %number argument: - # use the same <number> passed as an argument - job_id=${jobspec} ;; - ""|%|+) # empty, %% or %+ argument: - # use the current job, which appears with a + in $jobstates: - # suspended:+:5071=suspended (tty output) - job_id=${(k)jobstates[(r)*:+:*]} ;; - -) # %- argument: - # use the previous job, which appears with a - in $jobstates: - # suspended:-:6493=suspended (signal) - job_id=${(k)jobstates[(r)*:-:*]} ;; - [?]*) # %?string argument: - # use $jobtexts to match for a job whose command *contains* <string> - job_id=${(k)jobtexts[(r)*${(Q)jobspec}*]} ;; - *) # %string argument: - # use $jobtexts to match for a job whose command *starts with* <string> - job_id=${(k)jobtexts[(r)${(Q)jobspec}*]} ;; - esac - - # override preexec function arguments with job command - if [[ -n "${jobtexts[$job_id]}" ]]; then - 1="${jobtexts[$job_id]}" - 2="${jobtexts[$job_id]}" - fi - fi - - # cmd name only, or if this is sudo or ssh, the next cmd - local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%} - local LINE="${2:gs/%/%%}" - - title '$CMD' '%100>...>$LINE%<<' -} - # URL-encode a string # # Encodes a string using RFC 2396 URL-encoding (%-escaped). @@ -352,21 +366,6 @@ function zsh_urlencode() { echo -E "$url_str" } -# Emits the control sequence to notify many terminal emulators -# of the cwd -# -# Identifies the directory using a file: URI scheme, including -# the host name to disambiguate local vs. remote paths. -function mzc_termsupport_cwd { - # Percent-encode the host and path names. - local URL_HOST URL_PATH - URL_HOST="$(zsh_urlencode -P $HOST)" || return 1 - URL_PATH="$(zsh_urlencode -P $PWD)" || return 1 - - # common control sequence (OSC 7) to set current host and path - printf "\e]7;%s\a" "file://${URL_HOST}${URL_PATH}" -} - if [ -f env.sh ]; then source ./env.sh fi |
