Skip to content

Commit

Permalink
refactor(dry run): idiomatic zsh for boolean variable
Browse files Browse the repository at this point in the history
  • Loading branch information
olets committed Apr 5, 2020
1 parent 5d216e4 commit 3572d06
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions zsh-abbr.zsh
Expand Up @@ -20,10 +20,10 @@ ZSH_ABBR_USER_PATH="${ZSH_ABBR_USER_PATH="${HOME}/.config/zsh/abbreviations"}"

_zsh_abbr() {
{
local action number_opts opt opt_dry_run release_date scope \
local action number_opts opt dry_run release_date scope \
should_exit text_bold text_reset type version
dry_run=0
number_opts=0
opt_dry_run=false
release_date="March 22 2020"
should_exit=false
text_bold="\\033[1m"
Expand Down Expand Up @@ -206,7 +206,7 @@ _zsh_abbr() {
add $_alias
done < <(alias -g)

if ! $opt_dry_run; then
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
}
Expand All @@ -233,7 +233,7 @@ _zsh_abbr() {
util_add $abbreviation $expansion
done < $input_file

if ! $opt_dry_run; then
if ! (( dry_run )); then
echo "Abbreviations imported. It is recommended that you look over \$ZSH_ABBR_USER_PATH to confirm there are no quotation mark-related problems\\n"
fi
}
Expand All @@ -259,7 +259,7 @@ _zsh_abbr() {
util_add "g$key" "git ${value# }"
done

if ! $opt_dry_run; then
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
}
Expand Down Expand Up @@ -348,7 +348,7 @@ _zsh_abbr() {
if [[ -n "$expansion" ]]; then
util_add $new_abbreviation $expansion

if ! $opt_dry_run; then
if ! (( dry_run )); then
erase $current_abbreviation
else
echo "abbr -e $current_abbreviation"
Expand Down Expand Up @@ -390,15 +390,15 @@ _zsh_abbr() {
if [[ $scope == 'session' ]]; then
if [[ $type == 'global' ]]; then
if ! (( ${+ZSH_ABBR_SESSION_GLOBALS[$abbreviation]} )); then
if $opt_dry_run; then
if (( dry_run )); then
echo "abbr -S -g $abbreviation=${(Q)expansion}"
else
ZSH_ABBR_SESSION_GLOBALS[$abbreviation]=$expansion
fi
success=true
fi
elif ! (( ${+ZSH_ABBR_SESSION_COMMANDS[$abbreviation]} )); then
if $opt_dry_run; then
if (( dry_run )); then
echo "abbr -S $abbreviation=${(Q)expansion}"
else
ZSH_ABBR_SESSION_COMMANDS[$abbreviation]=$expansion
Expand All @@ -410,7 +410,7 @@ _zsh_abbr() {
source "${TMPDIR:-/tmp/}zsh-user-global-abbreviations"

if ! (( ${+ZSH_ABBR_USER_GLOBALS[$abbreviation]} )); then
if $opt_dry_run; then
if (( dry_run )); then
echo "abbr -g $abbreviation=${(Q)expansion}"
else
ZSH_ABBR_USER_GLOBALS[$abbreviation]=$expansion
Expand All @@ -422,7 +422,7 @@ _zsh_abbr() {
source "${TMPDIR:-/tmp/}zsh-user-abbreviations"

if ! (( ${+ZSH_ABBR_USER_COMMANDS[$abbreviation]} )); then
if $opt_dry_run; then
if (( dry_run )); then
echo "abbr ${(Q)abbreviation}=${(Q)expansion}"
else
ZSH_ABBR_USER_COMMANDS[$abbreviation]=$expansion
Expand Down Expand Up @@ -618,7 +618,7 @@ _zsh_abbr() {
util_set_once "action" "clear_session"
;;
--dry-run)
opt_dry_run=true
dry_run=1
((number_opts++))
;;
"--erase"|\
Expand Down

0 comments on commit 3572d06

Please sign in to comment.