diff --git a/forgit.plugin.sh b/forgit.plugin.sh index c023e7a..f047eb4 100755 --- a/forgit.plugin.sh +++ b/forgit.plugin.sh @@ -61,9 +61,7 @@ __forgit_get_git_color() { # git commit browser __forgit_log() { - if [[ __forgit_inside_work_tree -ne 0 ]]; then - return 1 - fi + __forgit_inside_work_tree || return local cmd="echo {} |grep -o '[a-f0-9]\{7\}' |head -1 |xargs -I% git show --color=always % $forgit_emojify $forgit_fancy" eval "git log --graph --color=always --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' $@ $forgit_emojify" | __forgit_fzf +s +m --tiebreak=index \ @@ -73,9 +71,7 @@ __forgit_log() { } __forgit_diff() { - if [[ __forgit_inside_work_tree -ne 0 ]]; then - return 1 - fi + __forgit_inside_work_tree || return local cmd="git diff --no-ext-diff --color=always -- {} $forgit_emojify $forgit_fancy" [[ $# -eq 0 ]] && local files=$(git rev-parse --show-toplevel) || local files="$@" git ls-files --modified "$files"| @@ -85,9 +81,7 @@ __forgit_diff() { } __forgit_add() { - if [[ __forgit_inside_work_tree -ne 0 ]]; then - return 1 - fi + __forgit_inside_work_tree || return added=$(__forgit_get_git_color "color.status.untracked" "red") changed=$(__forgit_get_git_color "color.status.changed" "red") unmerged=$(__forgit_get_git_color "color.status.unmerged" "red") @@ -105,9 +99,7 @@ __forgit_add() { __forgit_restore() { - if [[ __forgit_inside_work_tree -ne 0 ]]; then - return 1 - fi + __forgit_inside_work_tree || return local cmd="git diff --no-ext-diff --color=always -- {} $forgit_emojify $forgit_fancy" local files=$(git ls-files --modified $(git rev-parse --show-toplevel)| __forgit_fzf -m -0 --preview="$cmd") @@ -116,9 +108,7 @@ __forgit_restore() { } __forgit_clean() { - if [[ __forgit_inside_work_tree -ne 0 ]]; then - return 1 - fi + __forgit_inside_work_tree || return # Note: Postfix '/' in directory path should be removed. Otherwise the directory itself will not be removed. local files=$(git clean -xdfn "$@"| awk '{print $3}'| __forgit_fzf -m -0 |sed 's#/$##') [[ -n "$files" ]] && echo "$files" |xargs -I{} git clean -xdf {} && return