Skip to content

Commit 69fb7a3

Browse files
committed
feat(export aliases): respect the abbreviation's type
1 parent b6d9aa1 commit 69fb7a3

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,16 @@ git checkout
270270
#### Export Aliases
271271
272272
```shell
273-
abbr --export-aliases [DESTINATION]
273+
abbr --export-aliases [(--session | -S) | (--user | -U)] [(--global | -g)] [DESTINATION]
274274
```
275275
276-
Export abbreviations as aliases declarations.
276+
Export abbreviations as alias commands. Regular abbreviations follow global abbreviations. Session abbreviations follow user abbreviations.
277277
278-
To export session abbreviations, use the **--session** or **-S** scope flag. Otherwise, or if the **--user** or **-U** scope flag is used, cross-session abbreviations are exported.
278+
Use the **--session** or **-S** scope flag to export only session abbreviations. Use the **--user** or **-U** scope flag to export only user abbreviations.
279+
280+
Use the **--global** or **-g** type flag to export only global abbreviations. Use the **--regular** or **-r** type flag to export only regular abbreviations.
281+
282+
Combine a scope flag and a type flag to further limit the output.
279283
280284
```shell
281285
% abbr gcm="git checkout master"

zsh-abbr.zsh

+25-8
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,37 @@ _zsh_abbr() {
312312
}
313313

314314
function export_aliases() {
315-
local source
316-
local alias_definition
315+
local global_only
316+
317+
global_only=$opt_type_global
317318

318319
if [ $# -gt 1 ]; then
319320
util_error " export-aliases: Unexpected argument"
320321
return
321322
fi
322323

323-
if $opt_scope_session; then
324-
util_alias ZSH_ABBR_SESSION_GLOBALS $1
325-
util_alias ZSH_ABBR_SESSION_COMMANDS $1
326-
else
327-
util_alias ZSH_ABBR_USER_GLOBALS $1
328-
util_alias ZSH_ABBR_USER_COMMANDS $1
324+
if ! $opt_scope_user; then
325+
if ! $opt_type_regular; then
326+
opt_type_global=true
327+
util_alias ZSH_ABBR_SESSION_GLOBALS $1
328+
fi
329+
330+
if ! $global_only; then
331+
opt_type_global=false
332+
util_alias ZSH_ABBR_SESSION_COMMANDS $1
333+
fi
334+
fi
335+
336+
if ! $opt_scope_session; then
337+
if ! $opt_type_regular; then
338+
opt_type_global=true
339+
util_alias ZSH_ABBR_USER_GLOBALS $1
340+
fi
341+
342+
if ! $global_only; then
343+
opt_type_global=false
344+
util_alias ZSH_ABBR_USER_COMMANDS $1
345+
fi
329346
fi
330347
}
331348

0 commit comments

Comments
 (0)