From 272703b8cf7cbd8b5e17f18c5ca3e3558fce58a9 Mon Sep 17 00:00:00 2001 From: Kevin Zhuang Date: Thu, 28 Jan 2021 09:57:26 +1100 Subject: [PATCH 1/4] feat: added some basic/common purpose zle widget. #24 --- dotbare.plugin.zsh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/dotbare.plugin.zsh b/dotbare.plugin.zsh index 6412abe..dd15c0c 100644 --- a/dotbare.plugin.zsh +++ b/dotbare.plugin.zsh @@ -148,3 +148,39 @@ _dotbare_completion_git() { local compdef_name="dotbare" compdef "${compdef_name}"=git } + +_widget_dotbare_fadd() { + dotbare fadd +} + +_widget_dotbare_fedit() { + dotbare fedit +} + +_widget_dotbare_fcheckout() { + dotbare fcheckout +} + +_widget_dotbare_freset() { + dotbare freset +} + +_widget_dotbare_flog() { + dotbare flog +} + +_widget_dotbare_fgrep() { + dotbare fgrep +} + +_widget_dotbare_fstat() { + dotbare fstat +} + +zle -N dotbare-fadd _widget_dotbare_fadd +zle -N dotbare-fedit _widget_dotbare_fedit +zle -N dotbare-fcheckout _widget_dotbare_fcheckout +zle -N dotbare-freset _widget_dotbare_reset +zle -N dotbare-flog _widget_dotbare_flog +zle -N dotbare-fgrep _widget_dotbare_fgrep +zle -N dotbare-fstat _widget_dotbare_fstat From 6b376ce250c899424c410183b7f44e5163261bf6 Mon Sep 17 00:00:00 2001 From: Kevin Zhuang Date: Fri, 29 Jan 2021 09:48:41 +1100 Subject: [PATCH 2/4] feat: added dotbare-transform widget --- dotbare.plugin.zsh | 59 +++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/dotbare.plugin.zsh b/dotbare.plugin.zsh index dd15c0c..90227f1 100644 --- a/dotbare.plugin.zsh +++ b/dotbare.plugin.zsh @@ -149,33 +149,13 @@ _dotbare_completion_git() { compdef "${compdef_name}"=git } -_widget_dotbare_fadd() { - dotbare fadd -} - -_widget_dotbare_fedit() { - dotbare fedit -} - -_widget_dotbare_fcheckout() { - dotbare fcheckout -} - -_widget_dotbare_freset() { - dotbare freset -} - -_widget_dotbare_flog() { - dotbare flog -} - -_widget_dotbare_fgrep() { - dotbare fgrep -} - -_widget_dotbare_fstat() { - dotbare fstat -} +_widget_dotbare_fadd() { dotbare fadd; } +_widget_dotbare_fedit() { dotbare fedit; } +_widget_dotbare_fcheckout() { dotbare fcheckout; } +_widget_dotbare_freset() { dotbare freset; } +_widget_dotbare_flog() { dotbare flog; } +_widget_dotbare_fgrep() { dotbare fgrep; } +_widget_dotbare_fstat() { dotbare fstat; } zle -N dotbare-fadd _widget_dotbare_fadd zle -N dotbare-fedit _widget_dotbare_fedit @@ -184,3 +164,28 @@ zle -N dotbare-freset _widget_dotbare_reset zle -N dotbare-flog _widget_dotbare_flog zle -N dotbare-fgrep _widget_dotbare_fgrep zle -N dotbare-fstat _widget_dotbare_fstat + +_widget_git_transform_dotbare() { + local dotbare_cmd new_cmd + dotbare_cmd=$(alias | grep dotbare | cut -d'=' -f1 | head -n 1) + [[ -z "${dotbare_cmd}" ]] && dotbare_cmd="dotbare" + dotbare_cmd="${dotbare_cmd} -g" + new_cmd=$(echo "$BUFFER" \ + | awk -v dotbare="${dotbare_cmd}" '{ + if ($1 == "git") { + $1=dotbare + if ($2 ~ /(log|add|reset|checkout|status|stash|grep|untrack|stat)/) { + if ($2 == "status"){ + $2="stat" + } + $2="f"$2 + } + } + print $0 + }' + ) + BUFFER="${new_cmd} " + zle end-of-line +} + +zle -N dotbare-transform _widget_git_transform_dotbare From 62e2c66a0ccacbab02746065fd62c362eb3c366b Mon Sep 17 00:00:00 2001 From: Kevin Zhuang Date: Fri, 29 Jan 2021 10:55:49 +1100 Subject: [PATCH 3/4] fix: dotbare-transform unwanted space --- dotbare.plugin.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dotbare.plugin.zsh b/dotbare.plugin.zsh index 90227f1..e73bcef 100644 --- a/dotbare.plugin.zsh +++ b/dotbare.plugin.zsh @@ -170,7 +170,7 @@ _widget_git_transform_dotbare() { dotbare_cmd=$(alias | grep dotbare | cut -d'=' -f1 | head -n 1) [[ -z "${dotbare_cmd}" ]] && dotbare_cmd="dotbare" dotbare_cmd="${dotbare_cmd} -g" - new_cmd=$(echo "$BUFFER" \ + BUFFER=$(echo "$BUFFER" \ | awk -v dotbare="${dotbare_cmd}" '{ if ($1 == "git") { $1=dotbare @@ -184,7 +184,6 @@ _widget_git_transform_dotbare() { print $0 }' ) - BUFFER="${new_cmd} " zle end-of-line } From 3d54dbb15b7a00a466807c9a05ae32da15dc3aa2 Mon Sep 17 00:00:00 2001 From: Kevin Zhuang Date: Wed, 3 Mar 2021 22:44:08 +1100 Subject: [PATCH 4/4] docs: update changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86b893c..9519e45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ Noteble changes are documentated in this file. - unnecessary argument for zsh completion [#26](https://github.com/kazhala/dotbare/issues/26) +### Added + +- common basic zsh widgets such as `dotbare fedit` [#24](https://github.com/kazhala/dotbare/issues/24) +- new zsh widget `dotbare-transform` (Not documented yet, will add to documendation in next release) + - transform a generic `git` command to a `dotbare` command; e.g. `git log` -> `dotbare -g flog` + - Bind this widget to keys of your choice (e.g. `ctrl-u`): `bindkey "^u" dotbare-transform` + ## 1.3.1 (25/08/2020) ### Fixed