From c1446b4750a31506daba7fc7d41957dd515e8022 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Sat, 6 Jul 2019 12:10:30 -0400 Subject: Automatic title: Replace fg with description from jobs --- lib/termsupport.zsh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index aa14f3f07..a74ad9922 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -72,7 +72,19 @@ function omz_termsupport_preexec { local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%} local LINE="${2:gs/%/%%}" - title '$CMD' '%100>...>$LINE%<<' + if [[ "$CMD" = fg ]]; then + # replace fg, possibly with argument, with description from jobs + local JOB + if [[ ${(z)1} = fg ]]; then # no arguments + JOB="$(jobs %%)" + else # arguments + JOB="$(jobs ${${(z)1}[2]})" + fi + JOB="${${(z)JOB}[4,$]}" # trim job number, +, pid, status + title ${JOB:gs/%/%%} ${JOB:gs/%/%%} + else + title '$CMD' '%100>...>$LINE%<<' + fi } precmd_functions+=(omz_termsupport_precmd) -- cgit v1.2.3-70-g09d2 From 902e3172c9b991ca0995a0dcd658caa29b918d8e Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Sun, 7 Jul 2019 10:48:36 -0400 Subject: Avoid error messages when there is no job --- lib/termsupport.zsh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index a74ad9922..59a1efb02 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -72,19 +72,22 @@ function omz_termsupport_preexec { local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%} local LINE="${2:gs/%/%%}" + # replace fg, possibly with argument, with description from jobs if [[ "$CMD" = fg ]]; then - # replace fg, possibly with argument, with description from jobs local JOB if [[ ${(z)1} = fg ]]; then # no arguments - JOB="$(jobs %%)" + JOB="$(jobs %% 2>/dev/null)" else # arguments - JOB="$(jobs ${${(z)1}[2]})" + JOB="$(jobs ${${(z)1}[2]} 2>/dev/null)" + fi + if [[ $? -eq 0 ]]; then + JOB="${${(z)JOB}[4,$]}" # trim job number, +, pid, status + title ${JOB:gs/%/%%} ${JOB:gs/%/%%} + return fi - JOB="${${(z)JOB}[4,$]}" # trim job number, +, pid, status - title ${JOB:gs/%/%%} ${JOB:gs/%/%%} - else - title '$CMD' '%100>...>$LINE%<<' fi + + title '$CMD' '%100>...>$LINE%<<' } precmd_functions+=(omz_termsupport_precmd) -- cgit v1.2.3-70-g09d2 From 888ab9091c4fb5bbadd1329524abfe9aa7a84451 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 28 Feb 2020 19:07:05 +0100 Subject: lib: add support for clippaste in WSL using powershell Source: https://github.com/microsoft/WSL/issues/4852#issuecomment-579616808 --- lib/clipboard.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh index 808f2ea2d..122145f15 100644 --- a/lib/clipboard.zsh +++ b/lib/clipboard.zsh @@ -83,7 +83,7 @@ function detect-clipboard() { function clippaste() { tmux save-buffer -; } elif [[ $(uname -r) = *icrosoft* ]]; then function clipcopy() { clip.exe < "${1:-/dev/stdin}"; } - function clippaste() { _retry_clipboard_detection_or_fail clippaste "$@"; } + function clippaste() { powershell.exe -noprofile -command Get-Clipboard; } else function _retry_clipboard_detection_or_fail() { local clipcmd="${1}"; shift -- cgit v1.2.3-70-g09d2 From a2cad16790aeb7e775da47fd11f1f7cee1e03c90 Mon Sep 17 00:00:00 2001 From: Stephen Heuer Date: Fri, 28 Feb 2020 12:50:17 -0600 Subject: lib: urlencode hostname in update_terminalapp_cwd (#6245) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apple's Terminal doesn't open a new tab in your current directory if your hostname has UTF-8 characters in it. Percent encoding the host in addition to the path in update_terminalapp_cwd appears to solve this issue. Co-authored-by: Marc Cornellà --- lib/termsupport.zsh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index f5e367fcb..19fd57b9d 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -91,12 +91,13 @@ if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then function update_terminalapp_cwd() { emulate -L zsh - # Percent-encode the pathname. - local URL_PATH="$(omz_urlencode -P $PWD)" - [[ $? != 0 ]] && return 1 + # Percent-encode the host and path names. + local URL_HOST URL_PATH + URL_HOST="$(omz_urlencode -P $HOST)" || return 1 + URL_PATH="$(omz_urlencode -P $PWD)" || return 1 # Undocumented Terminal.app-specific control sequence - printf '\e]7;%s\a' "file://$HOST$URL_PATH" + printf '\e]7;%s\a' "file://$URL_HOST$URL_PATH" } # Use a precmd hook instead of a chpwd hook to avoid contaminating output -- cgit v1.2.3-70-g09d2 From b6f2cfdb93627ca82ced24aaddb122b3a76a2638 Mon Sep 17 00:00:00 2001 From: Vital Kolas Date: Thu, 12 May 2016 10:40:24 +0300 Subject: Exclude .idea folder from grep search scope --- lib/grep.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/grep.zsh b/lib/grep.zsh index abc1650a1..886e36a8d 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -10,13 +10,13 @@ if grep-flag-available --color=auto; then GREP_OPTIONS+=" --color=auto" fi -# ignore VCS folders (if the necessary grep flags are available) -VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}" +# ignore these folders (if the necessary grep flags are available) +EXC_FOLDERS="{.bzr,CVS,.git,.hg,.svn,.idea}" if grep-flag-available --exclude-dir=.cvs; then - GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS" + GREP_OPTIONS+=" --exclude-dir=$EXC_FOLDERS" elif grep-flag-available --exclude=.cvs; then - GREP_OPTIONS+=" --exclude=$VCS_FOLDERS" + GREP_OPTIONS+=" --exclude=$EXC_FOLDERS" fi # export grep settings @@ -24,5 +24,5 @@ alias grep="grep $GREP_OPTIONS" # clean up unset GREP_OPTIONS -unset VCS_FOLDERS +unset EXC_FOLDERS unfunction grep-flag-available -- cgit v1.2.3-70-g09d2 From b4b50f20ac7a6645d04993ba8ca8695a41b8db7a Mon Sep 17 00:00:00 2001 From: Peter Vandenberk Date: Wed, 10 Oct 2018 17:21:06 +0100 Subject: Also set options for egrep and fgrep --- lib/grep.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/grep.zsh b/lib/grep.zsh index 886e36a8d..bd9dad41f 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -19,8 +19,10 @@ elif grep-flag-available --exclude=.cvs; then GREP_OPTIONS+=" --exclude=$EXC_FOLDERS" fi -# export grep settings +# export grep, egrep and fgrep settings alias grep="grep $GREP_OPTIONS" +alias egrep="egrep $GREP_OPTIONS" +alias fgrep="fgrep $GREP_OPTIONS" # clean up unset GREP_OPTIONS -- cgit v1.2.3-70-g09d2 From a8ed1c4e7ab7e7df3a1e903cde30f94bf6da3e39 Mon Sep 17 00:00:00 2001 From: Shi Yan Date: Fri, 30 Nov 2018 15:44:41 +1100 Subject: Ignore .tox folder in grep --- lib/grep.zsh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/grep.zsh b/lib/grep.zsh index bd9dad41f..09042e13b 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -11,7 +11,7 @@ if grep-flag-available --color=auto; then fi # ignore these folders (if the necessary grep flags are available) -EXC_FOLDERS="{.bzr,CVS,.git,.hg,.svn,.idea}" +EXC_FOLDERS="{.bzr,CVS,.git,.hg,.svn,.idea,.tox}" if grep-flag-available --exclude-dir=.cvs; then GREP_OPTIONS+=" --exclude-dir=$EXC_FOLDERS" @@ -25,6 +25,5 @@ alias egrep="egrep $GREP_OPTIONS" alias fgrep="fgrep $GREP_OPTIONS" # clean up -unset GREP_OPTIONS -unset EXC_FOLDERS +unset GREP_OPTIONS EXC_FOLDERS unfunction grep-flag-available -- cgit v1.2.3-70-g09d2 From 57b178102c0016f5c433054ce981a80dd4b4b73f Mon Sep 17 00:00:00 2001 From: mattmc3 Date: Sat, 30 Nov 2019 13:49:23 -0500 Subject: Performance enhancement for lib/grep - Use $ZSH_CACHE_DIR to store the grep alias with all the right features - Expire the cache after 24 hours - See issue #8444 --- lib/grep.zsh | 57 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/grep.zsh b/lib/grep.zsh index 09042e13b..df9146aa4 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -1,29 +1,40 @@ -# is x grep argument available? -grep-flag-available() { - echo | grep $1 "" >/dev/null 2>&1 -} +# see if we already cached the grep alias in past day +_grep_alias_cache=("$ZSH_CACHE_DIR"/grep_alias.zsh(Nm-24)) +if (( $#_grep_alias_cache )); then + source "$ZSH_CACHE_DIR"/grep_alias.zsh +else + # is x grep argument available? + grep-flag-available() { + echo | grep $1 "" >/dev/null 2>&1 + } -GREP_OPTIONS="" + GREP_OPTIONS="" -# color grep results -if grep-flag-available --color=auto; then - GREP_OPTIONS+=" --color=auto" -fi + # color grep results + if grep-flag-available --color=auto; then + GREP_OPTIONS+=" --color=auto" + fi -# ignore these folders (if the necessary grep flags are available) -EXC_FOLDERS="{.bzr,CVS,.git,.hg,.svn,.idea,.tox}" + # ignore these folders (if the necessary grep flags are available) + EXC_FOLDERS="{.bzr,CVS,.git,.hg,.svn,.idea,.tox}" -if grep-flag-available --exclude-dir=.cvs; then - GREP_OPTIONS+=" --exclude-dir=$EXC_FOLDERS" -elif grep-flag-available --exclude=.cvs; then - GREP_OPTIONS+=" --exclude=$EXC_FOLDERS" -fi + if grep-flag-available --exclude-dir=.cvs; then + GREP_OPTIONS+=" --exclude-dir=$EXC_FOLDERS" + elif grep-flag-available --exclude=.cvs; then + GREP_OPTIONS+=" --exclude=$EXC_FOLDERS" + fi -# export grep, egrep and fgrep settings -alias grep="grep $GREP_OPTIONS" -alias egrep="egrep $GREP_OPTIONS" -alias fgrep="fgrep $GREP_OPTIONS" + { + # export grep, egrep and fgrep settings + echo alias grep="'grep $GREP_OPTIONS'" + echo alias egrep="'egrep $GREP_OPTIONS'" + echo alias fgrep="'fgrep $GREP_OPTIONS'" + } > "$ZSH_CACHE_DIR/grep_alias.zsh" -# clean up -unset GREP_OPTIONS EXC_FOLDERS -unfunction grep-flag-available + source "$ZSH_CACHE_DIR/grep_alias.zsh" + + # clean up + unset GREP_OPTIONS EXC_FOLDERS + unfunction grep-flag-available +fi +unset _grep_alias_cache -- cgit v1.2.3-70-g09d2 From 8d814fdff6f57e83a2b0c9430f61f7093a95bd04 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 1 Mar 2020 14:02:06 +0100 Subject: Fast algorithm to determine grep alias flags This version tries whether grep supports all the flags together and progressively checks older flags if the grep test fails. This means only one grep call if all flags are supported, and one additional call for every flag that's not supported, up to a maximum of 3 calls. --- lib/grep.zsh | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/grep.zsh b/lib/grep.zsh index df9146aa4..933de2990 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -4,37 +4,36 @@ if (( $#_grep_alias_cache )); then source "$ZSH_CACHE_DIR"/grep_alias.zsh else # is x grep argument available? - grep-flag-available() { - echo | grep $1 "" >/dev/null 2>&1 + grep-flags-available() { + echo | grep "$@" "" >/dev/null 2>&1 } GREP_OPTIONS="" - # color grep results - if grep-flag-available --color=auto; then - GREP_OPTIONS+=" --color=auto" - fi - # ignore these folders (if the necessary grep flags are available) EXC_FOLDERS="{.bzr,CVS,.git,.hg,.svn,.idea,.tox}" - if grep-flag-available --exclude-dir=.cvs; then - GREP_OPTIONS+=" --exclude-dir=$EXC_FOLDERS" - elif grep-flag-available --exclude=.cvs; then - GREP_OPTIONS+=" --exclude=$EXC_FOLDERS" + if grep-flags-available --color=auto --exclude-dir=.cvs; then + GREP_OPTIONS+="--color=auto --exclude-dir=$EXC_FOLDERS" + elif grep-flags-available --color=auto --exclude=.cvs; then + GREP_OPTIONS+="--color=auto --exclude=$EXC_FOLDERS" + elif grep-flags-available --color=auto; then + GREP_OPTIONS+="--color=auto" fi { - # export grep, egrep and fgrep settings - echo alias grep="'grep $GREP_OPTIONS'" - echo alias egrep="'egrep $GREP_OPTIONS'" - echo alias fgrep="'fgrep $GREP_OPTIONS'" + if [[ -n "$GREP_OPTIONS" ]]; then + # export grep, egrep and fgrep settings + echo alias grep="'grep $GREP_OPTIONS'" + echo alias egrep="'egrep $GREP_OPTIONS'" + echo alias fgrep="'fgrep $GREP_OPTIONS'" + fi } > "$ZSH_CACHE_DIR/grep_alias.zsh" source "$ZSH_CACHE_DIR/grep_alias.zsh" # clean up unset GREP_OPTIONS EXC_FOLDERS - unfunction grep-flag-available + unfunction grep-flags-available fi unset _grep_alias_cache -- cgit v1.2.3-70-g09d2 From dc190d872aa37dc0440284bee6c6bd7744007bf0 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 1 Mar 2020 20:17:38 +0100 Subject: Refactor grep.zsh file - Move grep-alias path to variable. - Use <<< "" instead of piped echo to check grep flags. - Remove check for --color only since it's the same release as --exclude. --- lib/grep.zsh | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/grep.zsh b/lib/grep.zsh index 933de2990..1d94eb978 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -1,39 +1,37 @@ -# see if we already cached the grep alias in past day -_grep_alias_cache=("$ZSH_CACHE_DIR"/grep_alias.zsh(Nm-24)) -if (( $#_grep_alias_cache )); then - source "$ZSH_CACHE_DIR"/grep_alias.zsh -else - # is x grep argument available? +__GREP_CACHE_FILE="$ZSH_CACHE_DIR"/grep-alias + +# See if there's a cache file modified in the last day +__GREP_ALIAS_CACHES=("$__GREP_CACHE_FILE"(Nm-1)) +if [[ -z "$__GREP_ALIAS_CACHES" ]]; then grep-flags-available() { - echo | grep "$@" "" >/dev/null 2>&1 + command grep "$@" "" &>/dev/null <<< "" } - GREP_OPTIONS="" - - # ignore these folders (if the necessary grep flags are available) + # Ignore these folders (if the necessary grep flags are available) EXC_FOLDERS="{.bzr,CVS,.git,.hg,.svn,.idea,.tox}" + # Check for --exclude-dir, otherwise check for --exclude. If --exclude + # isn't available, --color won't be either (they were released at the same + # time (v2.5): http://git.savannah.gnu.org/cgit/grep.git/tree/NEWS?id=1236f007 if grep-flags-available --color=auto --exclude-dir=.cvs; then - GREP_OPTIONS+="--color=auto --exclude-dir=$EXC_FOLDERS" + GREP_OPTIONS="--color=auto --exclude-dir=$EXC_FOLDERS" elif grep-flags-available --color=auto --exclude=.cvs; then - GREP_OPTIONS+="--color=auto --exclude=$EXC_FOLDERS" - elif grep-flags-available --color=auto; then - GREP_OPTIONS+="--color=auto" + GREP_OPTIONS="--color=auto --exclude=$EXC_FOLDERS" fi { if [[ -n "$GREP_OPTIONS" ]]; then # export grep, egrep and fgrep settings - echo alias grep="'grep $GREP_OPTIONS'" - echo alias egrep="'egrep $GREP_OPTIONS'" - echo alias fgrep="'fgrep $GREP_OPTIONS'" + echo "alias grep='grep $GREP_OPTIONS'" + echo "alias egrep='egrep $GREP_OPTIONS'" + echo "alias fgrep='fgrep $GREP_OPTIONS'" fi - } > "$ZSH_CACHE_DIR/grep_alias.zsh" + } > "$__GREP_CACHE_FILE" - source "$ZSH_CACHE_DIR/grep_alias.zsh" - - # clean up + # Clean up unset GREP_OPTIONS EXC_FOLDERS unfunction grep-flags-available fi -unset _grep_alias_cache + +source "$__GREP_CACHE_FILE" +unset __GREP_CACHE_FILE __GREP_ALIAS_CACHES -- cgit v1.2.3-70-g09d2 From d3dfc1371693d2b64ccec249511ea9178b088015 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 2 Mar 2020 12:35:58 +0100 Subject: lib: use grep-alias cache only if ZSH_CACHE_DIR is writable Fixes #8693 --- lib/grep.zsh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/grep.zsh b/lib/grep.zsh index 1d94eb978..a725e0f26 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -2,7 +2,9 @@ __GREP_CACHE_FILE="$ZSH_CACHE_DIR"/grep-alias # See if there's a cache file modified in the last day __GREP_ALIAS_CACHES=("$__GREP_CACHE_FILE"(Nm-1)) -if [[ -z "$__GREP_ALIAS_CACHES" ]]; then +if [[ -n "$__GREP_ALIAS_CACHES" ]]; then + source "$__GREP_CACHE_FILE" +else grep-flags-available() { command grep "$@" "" &>/dev/null <<< "" } @@ -12,26 +14,28 @@ if [[ -z "$__GREP_ALIAS_CACHES" ]]; then # Check for --exclude-dir, otherwise check for --exclude. If --exclude # isn't available, --color won't be either (they were released at the same - # time (v2.5): http://git.savannah.gnu.org/cgit/grep.git/tree/NEWS?id=1236f007 + # time (v2.5): https://git.savannah.gnu.org/cgit/grep.git/tree/NEWS?id=1236f007 if grep-flags-available --color=auto --exclude-dir=.cvs; then GREP_OPTIONS="--color=auto --exclude-dir=$EXC_FOLDERS" elif grep-flags-available --color=auto --exclude=.cvs; then GREP_OPTIONS="--color=auto --exclude=$EXC_FOLDERS" fi - { - if [[ -n "$GREP_OPTIONS" ]]; then - # export grep, egrep and fgrep settings - echo "alias grep='grep $GREP_OPTIONS'" - echo "alias egrep='egrep $GREP_OPTIONS'" - echo "alias fgrep='fgrep $GREP_OPTIONS'" + if [[ -n "$GREP_OPTIONS" ]]; then + # export grep, egrep and fgrep settings + alias grep="grep $GREP_OPTIONS" + alias egrep="egrep $GREP_OPTIONS" + alias fgrep="fgrep $GREP_OPTIONS" + + # write to cache file if cache directory is writable + if [[ -w "$ZSH_CACHE_DIR" ]]; then + alias -L grep egrep fgrep >| "$__GREP_CACHE_FILE" fi - } > "$__GREP_CACHE_FILE" + fi # Clean up unset GREP_OPTIONS EXC_FOLDERS unfunction grep-flags-available fi -source "$__GREP_CACHE_FILE" unset __GREP_CACHE_FILE __GREP_ALIAS_CACHES -- cgit v1.2.3-70-g09d2 From bbe54e4e6009dcbb69a4ace22ddae3672b323fdc Mon Sep 17 00:00:00 2001 From: Marek Dědič Date: Tue, 3 Mar 2020 13:46:06 +0100 Subject: lib: use `command` to run rm in upgrade function (#8696) --- lib/functions.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/functions.zsh b/lib/functions.zsh index 91e9cf895..f934ab968 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -8,7 +8,7 @@ function uninstall_oh_my_zsh() { function upgrade_oh_my_zsh() { env ZSH="$ZSH" sh "$ZSH/tools/upgrade.sh" - rm -rf "$ZSH/log/update.lock" + command rm -rf "$ZSH/log/update.lock" } function take() { -- cgit v1.2.3-70-g09d2 From d7825313cca7ec4cfdd0cf64fb9b0119d52a4ab7 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 3 Mar 2020 20:10:43 +0100 Subject: Use $jobstates and $jobtexts to look for jobs `jobs %string` doesn't work correctly when run inside `$()`. `$jobstates` and `$jobtexts` is available in the current shell process, so even though we need to replicate a bit more logic, every type of `fg` invocation works correctly. --- lib/termsupport.zsh | 53 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 59a1efb02..4d6fb8c21 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -68,25 +68,48 @@ function omz_termsupport_preexec { return fi + # 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 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* + job_id=${(k)jobtexts[(r)*${(Q)jobspec}*]} ;; + *) # %string argument: + # use $jobtexts to match for a job whose command *starts with* + job_id=${(k)jobtexts[(r)${(Q)jobspec}*]} ;; + esac + + # override preexec function arguments with job command + local job_cmd="${jobtexts[$job_id]}" + if [[ -n "$job_cmd" ]]; then + 1="$job_cmd" + 2="$job_cmd" + 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/%/%%}" - # replace fg, possibly with argument, with description from jobs - if [[ "$CMD" = fg ]]; then - local JOB - if [[ ${(z)1} = fg ]]; then # no arguments - JOB="$(jobs %% 2>/dev/null)" - else # arguments - JOB="$(jobs ${${(z)1}[2]} 2>/dev/null)" - fi - if [[ $? -eq 0 ]]; then - JOB="${${(z)JOB}[4,$]}" # trim job number, +, pid, status - title ${JOB:gs/%/%%} ${JOB:gs/%/%%} - return - fi - fi - title '$CMD' '%100>...>$LINE%<<' } -- cgit v1.2.3-70-g09d2 From 02d12538090a8ed74ccb15ef976fca46adcde37b Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 3 Mar 2020 20:17:01 +0100 Subject: lib: clean up termsupport.zsh --- lib/termsupport.zsh | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 4d6fb8c21..d67223caa 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -32,10 +32,10 @@ function title { # Try to use terminfo to set the title # If the feature is available set title if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then - echoti tsl - print -Pn "$1" - echoti fsl - fi + echoti tsl + print -Pn "$1" + echoti fsl + fi fi ;; esac @@ -50,24 +50,17 @@ fi # Runs before showing the prompt function omz_termsupport_precmd { - emulate -L zsh - - if [[ "$DISABLE_AUTO_TITLE" == true ]]; then - return - fi - + [[ "$DISABLE_AUTO_TITLE" == true ]] && return title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE } # Runs before executing the command function omz_termsupport_preexec { + [[ "$DISABLE_AUTO_TITLE" == true ]] && return + emulate -L zsh setopt extended_glob - if [[ "$DISABLE_AUTO_TITLE" == true ]]; then - return - fi - # split command into array of arguments local -a cmdargs cmdargs=("${(z)2}") @@ -99,10 +92,9 @@ function omz_termsupport_preexec { esac # override preexec function arguments with job command - local job_cmd="${jobtexts[$job_id]}" - if [[ -n "$job_cmd" ]]; then - 1="$job_cmd" - 2="$job_cmd" + if [[ -n "${jobtexts[$job_id]}" ]]; then + 1="${jobtexts[$job_id]}" + 2="${jobtexts[$job_id]}" fi fi -- cgit v1.2.3-70-g09d2 From 2eb3e9d57cf69f3c2fa557f9047e0a648d80b235 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 5 Mar 2020 17:26:16 +0100 Subject: lib: support konsole* $TERM in title function (#8035) --- lib/termsupport.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 654927a1c..3f71eb06a 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -17,7 +17,7 @@ function title { : ${2=$1} case "$TERM" in - cygwin|xterm*|putty*|rxvt*|ansi) + cygwin|xterm*|putty*|rxvt*|konsole*|ansi) print -Pn "\e]2;$2:q\a" # set window name print -Pn "\e]1;$1:q\a" # set tab name ;; -- cgit v1.2.3-70-g09d2 From 0caae9082a3bbb14b05938a7d0f292c2e4d161f4 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 5 Apr 2020 21:34:53 +0200 Subject: lib: speed up slow parts of the lib files; other small fixes --- lib/completion.zsh | 2 +- lib/functions.zsh | 2 +- lib/misc.zsh | 20 ++++++++++---------- lib/spectrum.zsh | 26 ++++++++++++-------------- 4 files changed, 24 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/completion.zsh b/lib/completion.zsh index c932bc925..8b87557a2 100644 --- a/lib/completion.zsh +++ b/lib/completion.zsh @@ -73,4 +73,4 @@ if [[ $COMPLETION_WAITING_DOTS = true ]]; then fi # automatically load bash completion functions -autoload -Uz bashcompinit && bashcompinit +autoload -U +X bashcompinit && bashcompinit diff --git a/lib/functions.zsh b/lib/functions.zsh index f934ab968..678e29ce7 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -89,7 +89,7 @@ function default() { # 0 if the env variable exists, 3 if it was set # function env_default() { - (( ${${(@f):-$(typeset +xg)}[(I)$1]} )) && return 0 + [[ ${parameters[$1]} = *-export* ]] && return 0 export "$1=$2" && return 3 } diff --git a/lib/misc.zsh b/lib/misc.zsh index 61571afc9..a5d3af998 100644 --- a/lib/misc.zsh +++ b/lib/misc.zsh @@ -3,15 +3,15 @@ autoload -Uz is-at-least # *-magic is known buggy in some versions; disable if so if [[ $DISABLE_MAGIC_FUNCTIONS != true ]]; then for d in $fpath; do - if [[ -e "$d/url-quote-magic" ]]; then - if is-at-least 5.1; then - autoload -Uz bracketed-paste-magic - zle -N bracketed-paste bracketed-paste-magic - fi - autoload -Uz url-quote-magic - zle -N self-insert url-quote-magic - break - fi + if [[ -e "$d/url-quote-magic" ]]; then + if is-at-least 5.1; then + autoload -Uz bracketed-paste-magic + zle -N bracketed-paste bracketed-paste-magic + fi + autoload -Uz url-quote-magic + zle -N self-insert url-quote-magic + break + fi done fi @@ -25,7 +25,7 @@ env_default 'LESS' '-R' alias _='sudo ' ## more intelligent acking for ubuntu users -if which ack-grep &> /dev/null; then +if (( $+commands[ack-grep] )); then alias afind='ack-grep -il' else alias afind='ack -il' diff --git a/lib/spectrum.zsh b/lib/spectrum.zsh index 312ab2248..d5c22a8c5 100644 --- a/lib/spectrum.zsh +++ b/lib/spectrum.zsh @@ -1,4 +1,3 @@ -#! /bin/zsh # A script to make using 256 colors in zsh less painful. # P.C. Shyamshankar # Copied from https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/ @@ -6,32 +5,31 @@ typeset -AHg FX FG BG FX=( - reset "%{%}" - bold "%{%}" no-bold "%{%}" - italic "%{%}" no-italic "%{%}" - underline "%{%}" no-underline "%{%}" - blink "%{%}" no-blink "%{%}" - reverse "%{%}" no-reverse "%{%}" + reset "%{%}" + bold "%{%}" no-bold "%{%}" + italic "%{%}" no-italic "%{%}" + underline "%{%}" no-underline "%{%}" + blink "%{%}" no-blink "%{%}" + reverse "%{%}" no-reverse "%{%}" ) for color in {000..255}; do - FG[$color]="%{[38;5;${color}m%}" - BG[$color]="%{[48;5;${color}m%}" + FG[$color]="%{[38;5;${color}m%}" + BG[$color]="%{[48;5;${color}m%}" done - -ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} - # Show all 256 colors with color number function spectrum_ls() { + local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} for code in {000..255}; do - print -P -- "$code: %{$FG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}" + print -P -- "$code: $FG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}" done } # Show all 256 colors where the background is set to specific color function spectrum_bls() { + local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} for code in {000..255}; do - print -P -- "$code: %{$BG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}" + print -P -- "$code: $BG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}" done } -- cgit v1.2.3-70-g09d2