Skip to content

Commit

Permalink
feat(git aliases): add unprefixed command aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
olets committed Apr 7, 2020
1 parent 2733d6b commit 4a7ab7e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
26 changes: 16 additions & 10 deletions README.md
Expand Up @@ -121,7 +121,7 @@ Your branch is up to date with 'origin/master'.

# Make the switch from aliases
% abbr --import-aliases
% abbr -g --import-git-aliases
% abbr --import-git-aliases
```

## Usage
Expand Down Expand Up @@ -169,7 +169,7 @@ Default is regular.
| (--help | -h)
| --import-aliases [(--global | -g)] [--dry-run]
| --import-fish [(--session | -S) | (--user | -U)] [(--global | -g)] [--dry-run] arg
| --import-git-aliases [(--session | -S) | (--user | -U)] [(--global | -g)] [--dry-run]
| --import-git-aliases [(--session | -S) | (--user | -U)] [--dry-run]
| (--list-abbreviations | -l) [(--session | -S) | (--user | -U)] [(--global | -g) | (--regular | -r)]
| (--list-commands | -L | -s) [(--session | -S) | (--user | -U)] [(--global | -g) | (--regular | -r)]
| (--rename | -R ) [(--session | -S) | (--user | -U)] [(--global | -g)] [(--global | -g)] [--dry-run] args
Expand Down Expand Up @@ -328,29 +328,35 @@ Use `--dry-run` to see what would result, without making any actual changes.
##### Git Aliases

```shell
abbr --import-git-aliases [(--global | -g)] [--dry-run]
abbr --import-git-aliases [--dry-run]
```

Add abbreviations for every Git alias available in the current session. WORDs are prefixed with `g`; EXPANSIONs are prefixed with `git[Space]`.
Add two abbreviations for every Git alias available in the current session: a global abbreviation where the WORD is prefixed with `g`, and a command abbreviation. For both the EXPANSION is prefixed with `git[Space]`.

Use the **--session** or **-S** scope flag to create session abbreviations. Otherwise, or if the **--user** or **-U** scope flag is used, the Git abbreviations will be user.

Use the **--global** or **-g** type flag to create global abbreviations.

```shell
% git config alias.co checkout

# session
% abbr --import-git-aliases -S
% gco[Space] # expands to git checkout
% gco[Space] # git checkout
% echo gco[Space] # echo git checkout
% co[Space] # git checkout
% echo co[Space] # echo co
% source ~/.zshrc
% gco[Space] # no expansion
% gco[Space] # gco

# user
% abbr --import-git-aliases
% gco[Space] # git checkout
% source ~/.zshrc
% gco[Space] # expands to git checkout
% gco[Space] # git checkout
```

Note for users migrating from Oh-My-Zsh: [OMZ's Git aliases are shell aliases](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git/git.plugin.zsh), not aliases in the Git config. To add abbreviations for them, use **import-aliases**.

Note that zsh-abbr does not lint the imported abbreviations. An effort is made to correctly wrap the expansion in single or double quotes, but it is possible that importing will add an abbreviation with a quotation mark problem in the expansion. It is up to the user to double check the result before taking further actions.
Note that zsh-abbr does not lint the imported abbreviations. It is up to the user to double check the result before taking further actions.

Use `--dry-run` to see what would result, without making any actual changes.

Expand Down
6 changes: 3 additions & 3 deletions man/abbr.txt
Expand Up @@ -20,7 +20,7 @@ SYNOPSIS

abbr --import-fish <file>

abbr --import-git-aliases [scope]
abbr --import-git-aliases

abbr --list

Expand Down Expand Up @@ -90,8 +90,8 @@ Options

o --import-git-aliases

Adds abbreviations for all git aliases. Abbreviations are pre-
fixed with "g", expansions are prefixed with "git ".
Adds two abbreviations for each git alias: a regular abbrevia-
tion, and a "g"-prefixed global abbreviation.


o abbr --list
Expand Down
4 changes: 2 additions & 2 deletions man/man1/abbr.1
Expand Up @@ -17,7 +17,7 @@ zsh\-abbr \- manage zsh abbreviations

\fBabbr \-\-import\-fish\fR <\fIfile\fR>

\fBabbr \-\-import\-git\-aliases\fR [\fIscope\fR]
\fBabbr \-\-import\-git\-aliases\fR

\fBabbr \-\-list\fR

Expand Down Expand Up @@ -79,7 +79,7 @@ Adds abbreviations exported from fish.
.IP \(bu
\fB\-\-import\-git\-aliases\fR

Adds abbreviations for all git aliases. Abbreviations are prefixed with "g", expansions are prefixed with "git ".
Adds two abbreviations for each git alias: a regular abbreviation, and a "g"-prefixed global abbreviation.

.IP \(bu
\fBabbr \-\-list\fR
Expand Down
8 changes: 4 additions & 4 deletions zsh-abbr.zsh
Expand Up @@ -272,13 +272,13 @@ _zsh_abbr() {
expansion=${(q)expansion}
fi

type="global"
_zsh_abbr:util_add "g$key" "git $value"

type="regular"
_zsh_abbr:util_add "$key" "git $value"
fi
done

if ! (( dry_run )); then
echo "Aliases imported. It is recommended that you look over \$ZSH_ABBR_USER_PATH to confirm there are no quotation mark-related problems\\n"
fi
}

function _zsh_abbr:list() {
Expand Down

0 comments on commit 4a7ab7e

Please sign in to comment.