From bbcb7fbf207d2cc634ab7d240b88192bd0da7b48 Mon Sep 17 00:00:00 2001 From: Wenxuan Date: Sat, 24 Mar 2018 10:23:17 +0800 Subject: [PATCH] Improve gi function Former-commit-id: e240d73260630a4425ed64b3f1a9cc6c76568bf1 --- forgit.plugin.zsh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index 0f707d6..23168ed 100644 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -65,11 +65,23 @@ gi() { local preview="echo {} |awk '{print \$2}' |xargs -I% bash -c 'cat $giCache/% 2>/dev/null || (curl -sL https://www.gitignore.io/api/% |tee $giCache/%)'" IFS=$'\n' [[ $# -gt 0 ]] && args=($@) || args=($(cat $giIndex |nl -nrn -w4 -s' ' |fzf -m --preview="$preview" --preview-window="right:70%" |awk '{print $2}')) - gi-get ${args[@]} -} -GI() { - inside_work_tree || return 1 - gi >> .gitignore + test -z "$args" && return 1 + local options=( + '(1) Output to stdout' + '(2) Append to .gitignore' + '(3) Overwrite .gitignore') + opt=$(printf '%s\n' "${options[@]}" |fzf |awk '{print $1}') + case "$opt" in + '(1)' ) + gi-get ${args[@]} + ;; + '(2)' ) + gi-get ${args[@]} >> .gitignore + ;; + '(3)' ) + gi-get ${args[@]} > .gitignore + ;; + esac } gi-update-index() { mkdir -p $giCache