Skip to content

feat(zkbd): allow zkbd to generate config in a custom directory#161

Open
sph432 wants to merge 6 commits intozsh-users:masterfrom
sph432:master
Open

feat(zkbd): allow zkbd to generate config in a custom directory#161
sph432 wants to merge 6 commits intozsh-users:masterfrom
sph432:master

Conversation

@sph432
Copy link
Copy Markdown

@sph432 sph432 commented Mar 9, 2026

No description provided.

Comment thread Doc/Zsh/contrib.yo Outdated
Comment thread Functions/Misc/zkbd Outdated
Comment thread Functions/Misc/zkbd Outdated

zkbd=${ZDOTDIR:-$HOME}/.zkbd
zparseopts -D -F -- d:=rawdir || return 1
[[ -n "$rawdir" ]] && zkbd="${rawdir[2]}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be simplified to zkbd=${rawdir[2]:-${ZDOTDIR:-$HOME}/.zkbd}

arguably it should check to see if an empty argument is given, since it could be the result of an error like a mistyped variable

i also don't think it should just silently ignore it if the directory doesn't exist

so maybe

if (( $#rawdir )); then
  zkbd=${rawdir[2]}
else
  zkbd=${ZDOTDIR:-$HOME}/.zkbd
fi

mkdir will catch the empty argument case

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplification accepted in 5de6025

zparseopts | return 1 handles the empty argument case just fine, even when explicitly specified:

% x -d''
x:zparseopts:1: missing argument for option: -d

regarding the 'accidental' mkdir, it happens with the default case as well, so maybe a warning about it in the docs would be more adequate: 799720f

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a missing argument, not an empty one. -d'' is the same thing as just -d

% () { local d; zparseopts -F - d:=d && print ok } -d ''
ok

in that case it will just silently use the default instead of alerting you to the mistake

not sure what you mean about accidental mkdir, i wasn't objecting to the directory being created. but not opposed to your clarification either

Copy link
Copy Markdown
Author

@sph432 sph432 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied requested changes.

Comment thread Doc/Zsh/contrib.yo Outdated
Comment thread Functions/Misc/zkbd Outdated
Comment thread Functions/Misc/zkbd Outdated

zkbd=${ZDOTDIR:-$HOME}/.zkbd
zparseopts -D -F -- d:=rawdir || return 1
[[ -n "$rawdir" ]] && zkbd="${rawdir[2]}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplification accepted in 5de6025

zparseopts | return 1 handles the empty argument case just fine, even when explicitly specified:

% x -d''
x:zparseopts:1: missing argument for option: -d

regarding the 'accidental' mkdir, it happens with the default case as well, so maybe a warning about it in the docs would be more adequate: 799720f

@sph432 sph432 requested a review from okdana April 6, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants