feat(shell): share env/aliases/functions between zsh and bash#1892
Merged
Conversation
Extract the portable parts of the zsh oh-my-zsh custom config into a shell-agnostic dotfiles/shell/ tree (00-env.sh, 10-aliases.sh, 40-functions.sh, 90-final.sh) installed at ~/.config/shell and sourced by both shells. The zsh custom files become thin wrappers that source these shared files, and bash sources them via programs.bash.initExtra in the right order. zsh-only bits (20-zle.zsh, 30-fzf.zsh) stay in zsh. Add a bash-only 20-bind.bash with the readline equivalent of the zsh ZLE keybindings (Home/End, Up/Down prefix history search, Ctrl-L clear+scrollback), guarded so it does not call the bind builtin in non-TTY shells. Functions are made bash-portable: the two setopt localoptions nounset pipefail calls become paired _shell_func_opts_on/off helpers, and [[ ... == /home/* ]] style tests become POSIX prefix tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make bash behave like zsh by sharing a single source of truth for the portable shell config, with no duplicated code maintained in two places.
Shared config (
dotfiles/shell/, installed at~/.config/shell)Portable (POSIX/bash) files sourced by both shells:
00-env.sh-- env vars, paths,ogcat, WEZTERM_HOSTNAME guard10-aliases.sh-- all aliases40-functions.sh-- all functions90-final.sh--fastfetchzsh wiring
The
.oh-my-zsh/custom/{00-env,10-aliases,40-functions,90-final}.zshfilesbecome thin wrappers that
sourcethe shared files. The zsh-only20-zle.zshand30-fzf.zshare left untouched (bash has no ZLE/fzf-zshequivalent and does not need one).
bash wiring
features/shell/bash/default.nixsources the shared files viaprograms.bash.initExtrain the same order zsh uses (env -> bind ->aliases -> functions -> final), and enables completion + history.
20-bind.bashis the bash-only readline equivalent of the zsh ZLEkeybindings (Home/End, Up/Down prefix history search, Ctrl-L
clear+scrollback), guarded so it does not call the
bindbuiltin innon-TTY shells.
Portability changes to functions
setopt localoptions nounset pipefailcalls become paired_shell_func_opts_on/_shell_func_opts_offhelpers.[[ "$HOME" == /home/* ]]style tests become POSIX prefix tests.Verification
nix evalof impacted hosts (desktops + servers) and theirhome-manager activation packages: clean.
shellcheckpasses on every shared file.type nr-> aliased toupdatenix,updatenixresolves as a function.