fzfgit.plugin.zsh (6469B) - raw
1 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" 2 0="${${(M)0:#/*}:-$PWD/$0}" 3 _path="${0:h}" 4 5 if [[ -z "${path[(r)$_path]}" ]]; then 6 path+=( "${_path}" ) 7 fi 8 9 __fzfgit_completion() { 10 local context state state_descr line ret curcontext 11 local -A opt_args 12 ret=1 13 curcontext="${curcontext}" 14 15 _arguments -C \ 16 '(- : *)'{-h,--help}'[show help information]' \ 17 '(- : *)'{-v,--version}'[display fzfgit version]' \ 18 '(-g --git)'{-g,--git}'[use fzfgit as a generic fuzzy git tool and operate in current git directory]' \ 19 '1:cmds:->cmds' \ 20 '*::options:->options' \ 21 && ret=0 22 23 case "${state}" in 24 cmds) 25 local subcommands 26 subcommands=( 27 'fadd:stage files' 28 'fbackup:backup files' 29 'fcheckout:checkout file/branch/commit' 30 'fedit:edit files' 31 'fzgrep:grep within tracked files' 32 'flog:interactive log viewer' 33 'freset:reset files/commit' 34 'fstash:stage management' 35 'fstat:toggle stage/unstage of files' 36 'funtrack:untrack files' 37 'fupgrade:update fzfgit' 38 ) 39 _describe 'command' subcommands \ 40 && ret=0 41 ;; 42 options) 43 case "${line[1]}" in 44 fadd) 45 _arguments \ 46 '(- : *)'{-h,--help}'[show help information]' \ 47 '(-f --file -d --dir -h --help)'{-f,--file}'[select files from PWD and stage]' \ 48 '(-d --dir -f --file -h --help)'{-d,--dir}'[select directory from PWD and stage]' \ 49 && ret=0 50 ;; 51 fbackup) 52 _arguments \ 53 '(- : *)'{-h,--help}'[show help information]' \ 54 '(-s --select -p --path -h --help)'{-s,--select}'[select tracked files to backup]' \ 55 '(-p --path -s --select -h --help)'{-p,--path}'[sepcify path of files to backup]:filename:_files' \ 56 '(-m --move -h --help)'{-m,--move}'[use mv cmd instead of cp cmd]' \ 57 && ret=0 58 ;; 59 fcheckout) 60 _arguments \ 61 '(- : *)'{-h,--help}'[show help information]' \ 62 '(-s --select -b --branch -c --commit -h --help)'{-s,--select}'[select files and then checkout them in selected commits]' \ 63 '(-b --branch -s --select -c --commit -h --help)'{-b,--branch}'[checkout branch]' \ 64 '(-c --commit -b --branch -s --select -h --help)'{-c,--commit}'[checkout commit]' \ 65 '(-y --yes -h --help)'{-y,--yes}'[acknowledge all actions and skip confirmation]' \ 66 && ret=0 67 ;; 68 fedit) 69 _arguments \ 70 '(- : *)'{-h,--help}'[show help information]' \ 71 '(-m --modified -c --commit -h --help)'{-m,--modified}'[edit modified files]' \ 72 '(-c --commit -m --modified -h --help)'{-c,--commit}'[edit commits]' \ 73 && ret=0 74 ;; 75 fzgrep) 76 _arguments \ 77 '(- : *)'{-h,--help}'[show help information]' \ 78 '(-f --full -c --col)'{-f,--full}'[include all columns during fzf search, as if using "--col 1"]' \ 79 '(-f --full -c --col)'{-c,--col}'[specify a column number to start searching in fzf]: :->cols' \ 80 && ret=0 81 ;; 82 flog) 83 _arguments \ 84 '(- : *)'{-h,--help}'[show help information]' \ 85 '(-r --revert -R --reset -e --edit -c --checkout -h --help)'{-r,--revert}'[revert the selected commit and skip action menu]' \ 86 '(-r --revert -R --reset -e --edit -c --checkout -h --help)'{-R,--reset}'[reset the selected commit and skip action menu]' \ 87 '(-r --revert -R --reset -e --edit -c --checkout -h --help)'{-e,--edit}'[edit the selected commit and skip action menu]' \ 88 '(-r --revert -R --reset -e --edit -c --checkout -h --help)'{-c,--checkout}'[checkout the selected commit and skip action menu]' \ 89 '(-y --yes -h --help)'{-y,--yes}'[acknowledge all actions and skip confirmation]' \ 90 && ret=0 91 ;; 92 freset) 93 _arguments \ 94 '(- : *)'{-h,--help}'[show help information]' \ 95 '(-c --commit -h --help)'{-c,--commit}'[reset HEAD to certain commit]' \ 96 '(-S --soft -H --hard -h --help)'{-S,--soft}'[reset commit using --soft flag]' \ 97 '(-H --hard -S --soft -h --help)'{-H,--hard}'[reset commit using --hard flag]' \ 98 '(-y --yes -h --help)'{-y,--yes}'[acknowledge all actions and skip confirmation]' \ 99 && ret=0 100 ;; 101 fstash) 102 _arguments \ 103 '(- : *)'{-h,--help}'[show help information]' \ 104 '(-s --select -d --delete -p --pop -h --help)'{-s,--select}'[list modified files and stash the selected files]' \ 105 '(-s --select -d --delete -p --pop -h --help)'{-d,--delete}'[list stash and delete the selected stash]' \ 106 '(-s --select -d --delete -p --pop -h --help)'{-p,--pop}'[use "stash pop" instead of "stash apply"]' \ 107 && ret=0 108 ;; 109 fstat) 110 _arguments \ 111 '(- : *)'{-h,--help}'[show help information]' \ 112 && ret=0 113 ;; 114 funtrack) 115 _arguments \ 116 '(- : *)'{-h,--help}'[show help information]' \ 117 '(-t --temp -r --resume -h --help)'{-t,--temp}'[temporarily ignore changes of the selected files]' \ 118 '(-t --temp -r --resume -h --help)'{-r,--resume}'[resume tracking changes of the selected files]' \ 119 '(-y --yes -h --help)'{-y,--yes}'[acknowledge all actions and skip confirmation]' \ 120 && ret=0 121 ;; 122 fupgrade) 123 _arguments \ 124 '(- : *)'{-h,--help}'[show help information]' \ 125 && ret=0 126 ;; 127 *) 128 _normal 129 ;; 130 esac 131 ;; 132 esac 133 134 return "${ret}"; 135 } 136 137 _fzfgit_completion_cmd() { 138 local compdef_name="fzfgit" 139 compdef __fzfgit_completion "${compdef_name}" 140 } 141 142 _fzfgit_completion_git() { 143 local compdef_name="fzfgit" 144 compdef "${compdef_name}"=git 145 } 146 147 _widget_fzfgit_fadd() { fadd; } 148 _widget_fzfgit_fedit() { fedit; } 149 _widget_fzfgit_fcheckout() { fcheckout; } 150 _widget_fzfgit_freset() { freset; } 151 _widget_fzfgit_flog() { flog; } 152 _widget_fzfgit_fzgrep() { fzgrep; } 153 _widget_fzfgit_fstat() { fstat; } 154 155 zle -N fzfgit-fadd _widget_fzfgit_fadd 156 zle -N fzfgit-fedit _widget_fzfgit_fedit 157 zle -N fzfgit-fcheckout _widget_fzfgit_fcheckout 158 zle -N fzfgit-freset _widget_fzfgit_reset 159 zle -N fzfgit-flog _widget_fzfgit_flog 160 zle -N fzfgit-fzgrep _widget_fzfgit_fzgrep 161 zle -N fzfgit-fstat _widget_fzfgit_fstat