From f404c5ba9fe9b3ad30ddc345afb112df3ecc6240 Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Wed, 17 Feb 2016 10:09:36 -0500 Subject: [PATCH 01/10] [prompt] update "pure" theme submodule --- modules/prompt/external-themes/pure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/prompt/external-themes/pure b/modules/prompt/external-themes/pure index 9e4955c..fb4c37d 160000 --- a/modules/prompt/external-themes/pure +++ b/modules/prompt/external-themes/pure @@ -1 +1 @@ -Subproject commit 9e4955cf91830dbb13fb405652af6d3b6ea07186 +Subproject commit fb4c37dad3c5cbdebca61a8ff5545397c11d450f From 858352ebf979949ff9e07650206b915f48fc30f4 Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Wed, 17 Feb 2016 23:57:41 -0500 Subject: [PATCH 02/10] add issue and PR templates --- ISSUE_TEMPLATE.md | 23 +++++++++++++++++++++++ PULL_REQUEST_TEMPLATE.md | 1 + 2 files changed, 24 insertions(+) create mode 100644 ISSUE_TEMPLATE.md create mode 100644 PULL_REQUEST_TEMPLATE.md diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..3e37116 --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -0,0 +1,23 @@ +Please check the existing issues to make sure you're not duplicating a report. + +For bug reports, please provide the following information: + +- Zim commit ref: +- gist of .zimrc: +- Zsh version: +- gist of .zshrc: +- $(uname -mosr): + +Description +----------- + + +Steps to reproduce +------------------ + + +Images or other information +--------------------------- + + + diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..663f1c4 --- /dev/null +++ b/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1 @@ +Please follow Zim's [code style guidelines](https://github.com/Eriner/zim/wiki/Code-Style-Guide). From b9595699a1055813633451f630a10b1cc48ecbbf Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Thu, 18 Feb 2016 00:04:06 -0500 Subject: [PATCH 03/10] use markdown MIT license --- LICENSE | 9 --------- LICENSE.md | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) delete mode 100644 LICENSE create mode 100644 LICENSE.md diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 4c63517..0000000 --- a/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -(The MIT License) - -Copyright (c) 2015-2016 Matt Hamilton and contributors. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..0589535 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,25 @@ +The MIT License (MIT) +===================== + +Copyright (c) `2015-2016` `Matt Hamilton and contributors` + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. From ee512c85a96e0fa761d07de6839693821be28ee2 Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Sat, 27 Feb 2016 18:43:19 -0500 Subject: [PATCH 04/10] [completion] update submodule --- modules/completion/external | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/completion/external b/modules/completion/external index 99cc7ea..3a2bb87 160000 --- a/modules/completion/external +++ b/modules/completion/external @@ -1 +1 @@ -Subproject commit 99cc7ea060637884293f38efb0d192828adcf8ff +Subproject commit 3a2bb8781d32d05d1bf05deeeb476beb651e8272 From f19a0268eede65f205ae26286dc5b38420f7ba6c Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Sat, 27 Feb 2016 18:43:33 -0500 Subject: [PATCH 05/10] [syntax-highlighting] update submodule --- modules/syntax-highlighting/external | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/syntax-highlighting/external b/modules/syntax-highlighting/external index e500ca2..7044c19 160000 --- a/modules/syntax-highlighting/external +++ b/modules/syntax-highlighting/external @@ -1 +1 @@ -Subproject commit e500ca246286e15789869de98dfa70d78574cdb0 +Subproject commit 7044c1986e2f6b15eec27a03651207fccb0a2fbe From 03f15c44953e44433d4276c627e75cef3428751d Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Sat, 27 Feb 2016 19:43:19 -0500 Subject: [PATCH 06/10] [fasd] add initial fasd support [zlogin] zcompare fasd and all functions [fasd] trim non-zsh options [fasd] merge PR #75 from clvv/fasd [fasd] partial merge PR #77 from clvv/fasd This closes #24 --- modules/fasd/README.md | 14 + modules/fasd/functions/_fasd_preexec | 1 + modules/fasd/functions/_fasd_zsh_cmd_complete | 5 + modules/fasd/functions/fasd | 424 ++++++++++++++++++ modules/fasd/functions/fasd_cd | 8 + modules/fasd/init.zsh | 56 +++ templates/zlogin | 6 + 7 files changed, 514 insertions(+) create mode 100644 modules/fasd/README.md create mode 100644 modules/fasd/functions/_fasd_preexec create mode 100644 modules/fasd/functions/_fasd_zsh_cmd_complete create mode 100644 modules/fasd/functions/fasd create mode 100644 modules/fasd/functions/fasd_cd create mode 100644 modules/fasd/init.zsh diff --git a/modules/fasd/README.md b/modules/fasd/README.md new file mode 100644 index 0000000..2d85197 --- /dev/null +++ b/modules/fasd/README.md @@ -0,0 +1,14 @@ +fasd +==== + +[Fasd](https://github.com/clvv/fasd) (pronounced similar to "fast") is a command-line productivity booster. +Fasd offers quick access to files and directories for POSIX shells. It is +inspired by tools like [autojump](https://github.com/joelthelion/autojump), +[z](http://github.com/rupa/z) and [v](https://github.com/rupa/v). Fasd keeps +track of files and directories you have accessed, so that you can quickly +reference them in the command line. + +Contributing +------------ + +Contributions should be submitted [upstream to fasd](https://github.com/clvv/fasd). diff --git a/modules/fasd/functions/_fasd_preexec b/modules/fasd/functions/_fasd_preexec new file mode 100644 index 0000000..1157fac --- /dev/null +++ b/modules/fasd/functions/_fasd_preexec @@ -0,0 +1 @@ +{ eval "fasd --proc $(fasd --sanitize $2)"; } >> "/dev/null" 2>&1 diff --git a/modules/fasd/functions/_fasd_zsh_cmd_complete b/modules/fasd/functions/_fasd_zsh_cmd_complete new file mode 100644 index 0000000..28d0680 --- /dev/null +++ b/modules/fasd/functions/_fasd_zsh_cmd_complete @@ -0,0 +1,5 @@ +# zsh command mode completion +local compl +read -c compl +(( $+compstate )) && compstate[insert]=menu # no expand if compsys loaded +reply=(${(f)"$(fasd --complete "$compl")"}) diff --git a/modules/fasd/functions/fasd b/modules/fasd/functions/fasd new file mode 100644 index 0000000..fc16ee7 --- /dev/null +++ b/modules/fasd/functions/fasd @@ -0,0 +1,424 @@ +# Fasd is originally written based on code from z (https://github.com/rupa/z) +# by rupa deadwyler under the WTFPL license. Most if not all of the code has +# been rewritten. + +# Copyright (C) 2011, 2012 by Wei Dai. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +# make zsh do word splitting inside this function +[ "$ZSH_VERSION" ] && emulate sh && setopt localoptions + +case $1 in +--init) shift + while [ "$1" ]; do + case $1 in + env) + { # Load configuration files + + if [[ -s ${XDG_CONFIG_HOME:-"${HOME}/.config"}/fasd/config ]]; then + source ${XDG_CONFIG_HOME:-"${HOME}/.config"}/fasd/config + else + [[ -s /etc/fasdrc ]] && source /etc/fasd + [[ -s ${HOME}/.fasdrc ]] && source ${HOME}/.fasdrc + fi + + # set default options + [ -z "$_FASD_DATA" ] && _FASD_DATA="$HOME/.fasd" + [ -z "$_FASD_BLACKLIST" ] && _FASD_BLACKLIST="--help" + [ -z "$_FASD_SHIFT" ] && _FASD_SHIFT="sudo busybox" + [ -z "$_FASD_IGNORE" ] && _FASD_IGNORE="fasd ls echo" + [ -z "$_FASD_SINK" ] && _FASD_SINK=/dev/null + [ -z "$_FASD_TRACK_PWD" ] && _FASD_TRACK_PWD=1 + [ -z "$_FASD_MAX" ] && _FASD_MAX=2000 + [ -z "$_FASD_BACKENDS" ] && _FASD_BACKENDS=native + [ -z "$_FASD_FUZZY" ] && _FASD_FUZZY=2 + [ -z "$_FASD_VIMINFO" ] && _FASD_VIMINFO="$HOME/.viminfo" + [ -z "$_FASD_RECENTLY_USED_XBEL" ] && \ + _FASD_RECENTLY_USED_XBEL="$HOME/.local/share/recently-used.xbel" + + if [ -z "$_FASD_AWK" ]; then + # awk preferences + local awk; for awk in mawk gawk original-awk nawk awk; do + $awk "" && _FASD_AWK=$awk && break + done + fi + } >> "${_FASD_SINK:-/dev/null}" 2>&1 + ;; + esac; shift + done + ;; + +# if "$_fasd_cur" or "$2" is a query, then output shell code to be eval'd +--word-complete-trigger) + shift; [ "$2" ] && local _fasd_cur="$2" || return + case $_fasd_cur in + ,*) printf %s\\n "$1 e $_fasd_cur";; + f,*) printf %s\\n "$1 f ${_fasd_cur#?}";; + d,*) printf %s\\n "$1 d ${_fasd_cur#?}";; + *,,) printf %s\\n "$1 e $_fasd_cur";; + *,,f) printf %s\\n "$1 f ${_fasd_cur%?}";; + *,,d) printf %s\\n "$1 d ${_fasd_cur%?}";; + esac + ;; + +--sanitize) shift; printf %s\\n "$*" | \ + sed 's/\([^\]\)$( *[^ ]* *\([^)]*\)))*/\1\2/g + s/\([^\]\)[|&;<>$`{}]\{1,\}/\1 /g' + ;; + +--proc) shift # process commands + # stop if we don't own $_FASD_DATA or $_FASD_RO is set + [ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return + + # blacklists + local each; for each in $_FASD_BLACKLIST; do + case " $* " in *\ $each\ *) return;; esac + done + + # shifts + while true; do + case " $_FASD_SHIFT " in + *\ $1\ *) shift;; + *) break;; + esac + done + + # ignores + case " $_FASD_IGNORE " in + *\ $1\ *) return;; + esac + + shift; fasd --add "$@" # add all arguments except command + ;; + +--add|-A) shift # add entries + # stop if we don't own $_FASD_DATA or $_FASD_RO is set + [ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return + + # find all valid path arguments, convert them to simplest absolute form + local paths="$(while [ "$1" ]; do + [ -e "$1" ] && printf %s\\n "$1"; shift + done | sed '/^[^/]/s@^@'"$PWD"'/@ + s@/\.\.$@/../@;s@/\(\./\)\{1,\}@/@g;:0 + s@[^/][^/]*//*\.\./@/@;t 0 + s@^/*\.\./@/@;s@//*@/@g;s@/\.\{0,1\}$@@;s@^$@/@' 2>> "$_FASD_SINK" \ + | tr '\n' '|')" + + # add current pwd if the option is set + [ "$_FASD_TRACK_PWD" = "1" -a "$PWD" != "$HOME" ] && paths="$paths|$PWD" + + [ -z "${paths##\|}" ] && return # stop if we have nothing to add + + # maintain the file + local tempfile + tempfile="$(mktemp "$_FASD_DATA".XXXXXX)" || return + $_FASD_AWK -v list="$paths" -v now="$(date +%s)" -v max="$_FASD_MAX" -F"|" ' + BEGIN { + split(list, files, "|") + for(i in files) { + path = files[i] + if(path == "") continue + paths[path] = path # array for checking + rank[path] = 1 + time[path] = now + } + } + $2 >= 1 { + if($1 in paths) { + rank[$1] = $2 + 1 / $2 + time[$1] = now + } else { + rank[$1] = $2 + time[$1] = $3 + } + count += $2 + } + END { + if(count > max) + for(i in rank) print i "|" 0.9*rank[i] "|" time[i] # aging + else + for(i in rank) print i "|" rank[i] "|" time[i] + }' "$_FASD_DATA" 2>> "$_FASD_SINK" >| "$tempfile" + if [ $? -ne 0 -a -f "$_FASD_DATA" ]; then + env rm -f "$tempfile" + else + env mv -f "$tempfile" "$_FASD_DATA" + fi + ;; + +--delete|-D) shift # delete entries + # stop if we don't own $_FASD_DATA or $_FASD_RO is set + [ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return + + # turn valid arguments into entry-deleting sed commands + local sed_cmd="$(while [ "$1" ]; do printf %s\\n "$1"; shift; done | \ + sed '/^[^/]/s@^@'"$PWD"'/@;s@/\.\.$@/../@;s@/\(\./\)\{1,\}@/@g;:0 + s@[^/][^/]*//*\.\./@/@;t 0 + s@^/*\.\./@/@;s@//*@/@g;s@/\.\{0,1\}$@@ + s@^$@/@;s@\([.[\/*^$]\)@\\\1@g;s@^\(.*\)$@/^\1|/d@' 2>> "$_FASD_SINK")" + + # maintain the file + local tempfile + tempfile="$(mktemp "$_FASD_DATA".XXXXXX)" || return + + sed "$sed_cmd" "$_FASD_DATA" 2>> "$_FASD_SINK" >| "$tempfile" + + if [ $? -ne 0 -a -f "$_FASD_DATA" ]; then + env rm -f "$tempfile" + else + env mv -f "$tempfile" "$_FASD_DATA" + fi + ;; + +--query) shift # query the db, --query [$typ ["$fnd" [$mode]]] + [ -f "$_FASD_DATA" ] || return # no db yet + [ "$1" ] && local typ="$1" + [ "$2" ] && local fnd="$2" + [ "$3" ] && local mode="$3" + + # cat all backends + local each _fasd_data; for each in $_FASD_BACKENDS; do + _fasd_data="$_fasd_data +$(fasd --backend $each)" + done + [ "$_fasd_data" ] || _fasd_data="$(cat "$_FASD_DATA")" + + # set mode specific code for calculating the prior + case $mode in + rank) local prior='times[i]';; + recent) local prior='sqrt(100000/(1+t-la[i]))';; + *) local prior='times[i] * frecent(la[i])';; + esac + + if [ "$fnd" ]; then # dafault matching + local bre="$(printf %s\\n "$fnd" | sed 's/\([*\.\\\[]\)/\\\1/g + s@ @[^|]*@g;s/\$$/|/')" + bre='^[^|]*'"$bre"'[^|/]*|' + local _ret="$(printf %s\\n "$_fasd_data" | grep "$bre")" + [ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do + [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" + done)" + if [ "$_ret" ]; then + _fasd_data="$_ret" + else # no case mathcing + _ret="$(printf %s\\n "$_fasd_data" | grep -i "$bre")" + [ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do + [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" + done)" + if [ "$_ret" ]; then + _fasd_data="$_ret" + elif [ "${_FASD_FUZZY:-0}" -gt 0 ]; then # fuzzy matching + local fuzzy_bre="$(printf %s\\n "$fnd" | \ + sed 's/\([*\.\\\[]\)/\\\1/g;s/\$$/|/ + s@\(\\\{0,1\}[^ ]\)@\1[^|/]\\{0,'"$_FASD_FUZZY"'\\}@g + s@ @[^|]*@g')" + fuzzy_bre='^[^|]*'"$fuzzy_bre"'[^|/]*|' + _ret="$(printf %s\\n "$_fasd_data" | grep -i "$fuzzy_bre")" + [ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do + [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" + done)" + [ "$_ret" ] && _fasd_data="$_ret" || _fasd_data= + fi + fi + else # no query arugments + _fasd_data="$(printf %s\\n "$_fasd_data" | while read -r line; do + [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" + done)" + fi + + # query the database + [ "$_fasd_data" ] && printf %s\\n "$_fasd_data" | \ + $_FASD_AWK -v t="$(date +%s)" -F"|" ' + function frecent(time) { + dx = t-time + if( dx < 3600 ) return 6 + if( dx < 86400 ) return 4 + if( dx < 604800 ) return 2 + return 1 + } + { + if(!paths[$1]) { + times[$1] = $2 + la[$1] = $3 + paths[$1] = 1 + } else { + times[$1] += $2 + if($3 > la[$1]) la[$1] = $3 + } + } + END { + for(i in paths) printf "%-10s %s\n", '"$prior"', i + }' - 2>> "$_FASD_SINK" + ;; + +--backend) + case $2 in + native) cat "$_FASD_DATA";; + viminfo) + < "$_FASD_VIMINFO" sed -n '/^>/{s@~@'"$HOME"'@ + s/^..// + p + }' | $_FASD_AWK -v t="$(date +%s)" '{ + t -= 60 + print $0 "|1|" t + }' + ;; + recently-used) + local nl="$(printf '\\\nX')"; nl="${nl%X}" # slash newline for sed + tr -d '\n' < "$_FASD_RECENTLY_USED_XBEL" | \ + sed 's@file:/@'"$nl"'@g;s@count="@'"$nl"'@g' | sed '1d;s/".*$//' | \ + tr '\n' '|' | sed 's@|/@'"$nl"'@g' | $_FASD_AWK -F'|' '{ + sum = 0 + for( i=2; i<=NF; i++ ) sum += $i + print $1 "|" sum + }' + ;; + current) + for path in *; do + printf "$PWD/%s|1\\n" "$path" + done + ;; + spotlight) + mdfind '(kMDItemFSContentChangeDate >= $time.today) || + kMDItemLastUsedDate >= $time.this_month' \ + | sed '/Library\//d + /\.app$/d + s/$/|2/' + ;; + *) eval "$2";; + esac + ;; + +*) # parsing logic and processing + local fnd= last= _FASD_BACKENDS="$_FASD_BACKENDS" _fasd_data= comp= exec= + while [ "$1" ]; do case $1 in + --complete) [ "$2" = "--" ] && shift; set -- $2; local lst=1 r=r comp=1;; + --query|--add|--delete|-A|-D) fasd "$@"; return $?;; + --version) [ -z "$comp" ] && echo "1.0.1" && return;; + --) while [ "$2" ]; do shift; fnd="$fnd $1"; last="$1"; done;; + -*) local o="${1#-}"; while [ "$o" ]; do case $o in + s*) local show=1;; + l*) local lst=1;; + i*) [ -z "$comp" ] && local interactive=1 show=1;; + r*) local mode=rank;; + t*) local mode=recent;; + e*) o="${o#?}"; if [ "$o" ]; then # there are characters after "-e" + local exec="$o" # anything after "-e" + else # use the next argument + local exec="${2:?"-e: Argument needed "}" + shift + fi; break;; + b*) o="${o#?}"; if [ "$o" ]; then + _FASD_BACKENDS="$o" + else + _FASD_BACKENDS="${2:?"-b: Argument needed"}" + shift + fi; break;; + B*) o="${o#?}"; if [ "$o" ]; then + _FASD_BACKENDS="$_FASD_BACKENDS $o" + else + _FASD_BACKENDS="$_FASD_BACKENDS ${2:?"-B: Argument needed"}" + shift + fi; break;; + a*) local typ=e;; + d*) local typ=d;; + f*) local typ=f;; + R*) local r=r;; + [0-9]*) local _fasd_i="$o"; break;; + h*) [ -z "$comp" ] && echo "fasd [options] [query ...] +[f|a|s|d|z] [options] [query ...] + options: + -s list paths with scores + -l list paths without scores + -i interactive mode + -e set command to execute on the result file + -b only use backend + -B add additional backend + -a match files and directories + -d match directories only + -f match files only + -r match by rank only + -t match by recent access only + -R reverse listing order + -h show a brief help message + -[0-9] select the nth entry + +fasd [-A|-D] [paths ...] + -A add paths + -D delete paths" >&2 && return;; + esac; o="${o#?}"; done;; + *) fnd="$fnd $1"; last="$1";; + esac; shift; done + + # guess whether the last query is selected from tab completion + case $last in + /?*) if [ -z "$show$lst" -a -${typ:-e} "$last" -a "$exec" ]; then + $exec "$last" + return + fi;; + esac + + local R; [ -z "$r" ] && R=r || R= # let $R be the opposite of $r + fnd="${fnd# }" + + local res + res="$(fasd --query 2>> "$_FASD_SINK")" # query the database + [ $? -gt 0 ] && return + if [ 0 -lt ${_fasd_i:-0} ] 2>> "$_FASD_SINK"; then + res="$(printf %s\\n "$res" | sort -n${R} | \ + sed -n "$_fasd_i"'s/^[^ ]*[ ]*//p')" + elif [ "$interactive" ] || [ "$exec" -a -z "$fnd$lst$show" -a -t 1 ]; then + if [ "$(printf %s "$res" | sed -n '$=')" -gt 1 ]; then + res="$(printf %s\\n "$res" | sort -n${R})" + printf %s\\n "$res" | sed = | sed 'N;s/\n/ /' | sort -nr >&2 + printf "> " >&2 + local i; read i; [ 0 -lt "${i:-0}" ] 2>> "$_FASD_SINK" || return 1 + fi + res="$(printf %s\\n "$res" | sed -n "${i:-1}"'s/^[^ ]*[ ]*//p')" + elif [ "$lst" ]; then + [ "$res" ] && printf %s\\n "$res" | sort -n${r} | sed 's/^[^ ]*[ ]*//' + return + elif [ "$show" ]; then + [ "$res" ] && printf %s\\n "$res" | sort -n${r} + return + elif [ "$fnd" ] && [ "$exec" -o ! -t 1 ]; then # exec or subshell + res="$(printf %s\\n "$res" | sort -n | sed -n '$s/^[^ ]*[ ]*//p')" + else # no args, show + [ "$res" ] && printf %s\\n "$res" | sort -n${r} + return + fi + if [ "$res" ]; then + fasd --add "$res" + [ -z "$exec" ] && exec='printf %s\n' + $exec "$res" + fi + ;; +esac + +#case $- in +# *i*) ;; # assume being sourced, do nothing +# *) # assume being executed as an executable +# if [ -x "$_FASD_SHELL" -a -z "$_FASD_SET" ]; then +# _FASD_SET=1 exec $_FASD_SHELL "$0" "$@" +# else +# fasd "$@" +# fi;; +#esac diff --git a/modules/fasd/functions/fasd_cd b/modules/fasd/functions/fasd_cd new file mode 100644 index 0000000..426d1c0 --- /dev/null +++ b/modules/fasd/functions/fasd_cd @@ -0,0 +1,8 @@ +# function to execute built-in cd +if [ $# -le 1 ]; then + fasd "$@" +else + local _fasd_ret="$(fasd -e 'printf %s' "$@")" + [ -z "$_fasd_ret" ] && return 1 + [ -d "$_fasd_ret" ] && cd "$_fasd_ret" || printf %s\n "$_fasd_ret" +fi diff --git a/modules/fasd/init.zsh b/modules/fasd/init.zsh new file mode 100644 index 0000000..7f86ea9 --- /dev/null +++ b/modules/fasd/init.zsh @@ -0,0 +1,56 @@ +fasd --init env + +alias a='fasd -a' +alias s='fasd -si' +alias sd='fasd -sid' +alias sf='fasd -sif' +alias d='fasd -d' +alias f='fasd -f' +alias z='fasd_cd -d' +alias zz='fasd_cd -d -i' + +# add zsh hook +autoload -Uz add-zsh-hook +add-zsh-hook preexec _fasd_preexec + +# enable command mode completion +compctl -U -K _fasd_zsh_cmd_complete -V fasd -x 'C[-1,-*e],s[-]n[1,e]' -c - \ + 'c[-1,-A][-1,-D]' -f -- fasd fasd_cd + +(( $+functions[compdef] )) && { + # zsh word mode completion + _fasd_zsh_word_complete() { + } + _fasd_zsh_word_complete_f() { _fasd_zsh_word_complete f ; } + _fasd_zsh_word_complete_d() { _fasd_zsh_word_complete d ; } + _fasd_zsh_word_complete_trigger() { + local _fasd_cur="${words[CURRENT]}" + eval $(fasd --word-complete-trigger _fasd_zsh_word_complete $_fasd_cur) + } + # define zle widgets + zle -C fasd-complete complete-word _generic + zstyle ':completion:fasd-complete:*' completer _fasd_zsh_word_complete + zstyle ':completion:fasd-complete:*' menu-select + + zle -C fasd-complete-f complete-word _generic + zstyle ':completion:fasd-complete-f:*' completer _fasd_zsh_word_complete_f + zstyle ':completion:fasd-complete-f:*' menu-select + + zle -C fasd-complete-d complete-word _generic + zstyle ':completion:fasd-complete-d:*' completer _fasd_zsh_word_complete_d + zstyle ':completion:fasd-complete-d:*' menu-select +} + +(( $+functions[compdef] )) && { + # enable word mode completion + orig_comp="$(zstyle -L ':completion:\*' completer 2>> "/dev/null")" + if [ "$orig_comp" ]; then + case $orig_comp in + *_fasd_zsh_word_complete_trigger*);; + *) eval "$orig_comp _fasd_zsh_word_complete_trigger";; + esac + else + zstyle ':completion:*' completer _complete _fasd_zsh_word_complete_trigger + fi + unset orig_comp +} diff --git a/templates/zlogin b/templates/zlogin index 959657d..6243dc5 100644 --- a/templates/zlogin +++ b/templates/zlogin @@ -30,12 +30,18 @@ zcompare ${zim_mods}/pacman/init.zsh zcompare ${zim_mods}/spectrum/init.zsh zcompare ${zim_mods}/completion/init.zsh + zcompare ${zim_mods}/fasd/init.zsh # zcompile all .zsh files in the custom module for file in ${zim_mods}/custom/**/^(README.md|*.zwc)(.); do zcompare ${file} done + # zcompile all autoloaded functions + for file in ${zim_mods}/**/functions/^(*.zwc)(.); do + zcompare ${file} + done + # syntax-highlighting for file in ${zim_mods}/syntax-highlighting/external/highlighters/**/*.zsh; do zcompare ${file} From 9b03840753c865215cc66133769babe336137fae Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Sun, 27 Mar 2016 18:46:59 -0400 Subject: [PATCH 07/10] [completion] update submodule --- modules/completion/external | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/completion/external b/modules/completion/external index 3a2bb87..3e81c15 160000 --- a/modules/completion/external +++ b/modules/completion/external @@ -1 +1 @@ -Subproject commit 3a2bb8781d32d05d1bf05deeeb476beb651e8272 +Subproject commit 3e81c156e7bb42b916138bf7990009a1ad78b517 From 7d254b2e839ed5c957d61d4dff8866353e18e7ef Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Sun, 27 Mar 2016 18:47:43 -0400 Subject: [PATCH 08/10] [substring-search] update submodule --- modules/history-substring-search/external | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/history-substring-search/external b/modules/history-substring-search/external index 7a4b54b..f5c164d 160000 --- a/modules/history-substring-search/external +++ b/modules/history-substring-search/external @@ -1 +1 @@ -Subproject commit 7a4b54b708ab88e0421097614f1acaa7a973c795 +Subproject commit f5c164d4c3af1f5bd068ee10f88b4c7b3a1fd841 From af608ab15b9524d058a53ab12079ab86143160f8 Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Sun, 27 Mar 2016 18:47:55 -0400 Subject: [PATCH 09/10] [syntax-highlighting] update submodule --- modules/syntax-highlighting/external | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/syntax-highlighting/external b/modules/syntax-highlighting/external index 7044c19..bc7f8ea 160000 --- a/modules/syntax-highlighting/external +++ b/modules/syntax-highlighting/external @@ -1 +1 @@ -Subproject commit 7044c1986e2f6b15eec27a03651207fccb0a2fbe +Subproject commit bc7f8ea433adf3efd71a3e950e9a8dec846a1171 From 983919fce4a96f1e4e6b84485ba52c19e1724928 Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Sun, 27 Mar 2016 18:48:11 -0400 Subject: [PATCH 10/10] [prompt] update "pure" theme submodule --- modules/prompt/external-themes/pure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/prompt/external-themes/pure b/modules/prompt/external-themes/pure index fb4c37d..c6564a4 160000 --- a/modules/prompt/external-themes/pure +++ b/modules/prompt/external-themes/pure @@ -1 +1 @@ -Subproject commit fb4c37dad3c5cbdebca61a8ff5545397c11d450f +Subproject commit c6564a4f7c0ab7a8ef62516278bdca2577432300