Skip to content

Commit c18a57d

Browse files
committed
feat(erase, rename): support dry run
1 parent 70d12b3 commit c18a57d

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

zsh-abbr.zsh

+27-12
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,47 @@ _zsh_abbr() {
9191
if [[ $scope == 'session' ]]; then
9292
if [[ $type == 'global' ]]; then
9393
if (( ${+ZSH_ABBR_SESSION_GLOBALS[$abbreviation]} )); then
94-
unset "ZSH_ABBR_SESSION_GLOBALS[${(b)abbreviation}]"
94+
if (( dry_run )); then
95+
echo "Erase ${type:-regular} ${scope:-user} abbreviation $abbeviation"
96+
else
97+
unset "ZSH_ABBR_SESSION_GLOBALS[${(b)abbreviation}]"
98+
fi
99+
95100
success=1
96101
fi
97102
elif (( ${+ZSH_ABBR_SESSION_COMMANDS[$abbreviation]} )); then
98-
unset "ZSH_ABBR_SESSION_COMMANDS[${(b)abbreviation}]"
103+
if (( dry_run )); then
104+
echo "Erase ${type:-regular} ${scope:-user} abbreviation $abbeviation"
105+
else
106+
unset "ZSH_ABBR_SESSION_COMMANDS[${(b)abbreviation}]"
107+
fi
108+
99109
success=1
100110
fi
101111
else
102112
if [[ $type == 'global' ]]; then
103113
source "${TMPDIR:-/tmp/}zsh-user-global-abbreviations"
104114

105115
if (( ${+ZSH_ABBR_USER_GLOBALS[$abbreviation]} )); then
106-
unset "ZSH_ABBR_USER_GLOBALS[${(b)abbreviation}]"
116+
if (( dry_run )); then
117+
echo "Erase ${type:-regular} ${scope:-user} abbreviation $abbeviation"
118+
else
119+
unset "ZSH_ABBR_USER_GLOBALS[${(b)abbreviation}]"
120+
fi
121+
107122
util_sync_user
108123
success=1
109124
fi
110125
else
111126
source "${TMPDIR:-/tmp/}zsh-user-abbreviations"
112127

113128
if (( ${+ZSH_ABBR_USER_COMMANDS[$abbreviation]} )); then
114-
unset "ZSH_ABBR_USER_COMMANDS[${(b)abbreviation}]"
129+
if (( dry_run )); then
130+
echo "Erase ${type:-regular} ${scope:-user} abbreviation $abbeviation"
131+
else
132+
unset "ZSH_ABBR_USER_COMMANDS[${(b)abbreviation}]"
133+
fi
134+
115135
util_sync_user
116136
success=1
117137
fi
@@ -121,7 +141,7 @@ _zsh_abbr() {
121141
_zsh_abbr_job_pop $job $job_group
122142

123143
if ! (( success )); then
124-
util_error " erase: No $type $scope abbreviation $abbreviation found"
144+
util_error " erase: No ${type:-regular} ${scope:-user} abbreviation $abbreviation found"
125145
fi
126146
}
127147

@@ -345,14 +365,9 @@ _zsh_abbr() {
345365
fi
346366
fi
347367

348-
if [[ -n "$expansion" ]]; then
368+
if [ $expansion ]; then
349369
util_add $new_abbreviation $expansion
350-
351-
if ! (( dry_run )); then
352-
erase $current_abbreviation
353-
else
354-
echo "abbr -e $current_abbreviation"
355-
fi
370+
erase $current_abbreviation
356371
else
357372
util_error " rename: No matching abbreviation $current_abbreviation exists"
358373
fi

0 commit comments

Comments
 (0)