Manage environment variables and aliases across bash, zsh, fish and other shells
# >>> shrc >>>
export EDITOR='vim'
alias ll='ls -la'
# <<< shrc <<<curl -LsSf https://raw.githubusercontent.com/tomasky/shrc/master/install.sh | bashsource <(curl -LsSf https://raw.githubusercontent.com/tomasky/shrc/master/install.sh)npm install -g @tomasko/shrc
npx @tomasko/shrc ls # or pnpm / yarn / bun, no global install neededmoon install kupas/shrc/cmd/shrcmoon add kupas/shrc| Platform | Asset |
|---|---|
| Linux x86-64 | shrc-linux-x86_64 (static, musl) |
| Linux arm64 | shrc-linux-aarch64 (static, musl) |
| macOS Apple silicon | shrc-darwin-aarch64 |
| Windows x86-64 | shrc-windows-x86_64.exe (MSVC) |
curl -LO https://github.com/tomasky/shrc/releases/latest/download/shrc-linux-x86_64
curl -LO https://github.com/tomasky/shrc/releases/latest/download/shrc-linux-x86_64.sha256
sha256sum -c shrc-linux-x86_64.sha256
install -m 755 shrc-linux-x86_64 ~/.local/bin/shrcgit clone https://github.com/tomasky/shrc && cd shrc
moon build --target native --release
./_build/native/release/build/cmd/shrc/shrc.exe helpshrc set EDITOR vim # environment variable, in every shell
shrc set NAME=VALUE # same, one argument
shrc set -a ll 'ls -la' # an alias instead of a variable
shrc set --prepend PATH /opt/bin # add a directory in front
shrc set --append PATH /opt/bin # add a directory at the end
shrc set --drop PATH /opt/bin # remove a directory
shrc set -r EDITOR '$HOME/bin/vi' # store shell syntax; references stay live
shrc rm EDITOR # remove every entry named EDITOR
shrc rm -a ll # remove only the alias
shrc ls # list managed entries
shrc ls EDIT # filter by name
shrc ls PATH # search paths, one directory per row, in order
shrc all # the manifest and every startup file
shrc init # import existing definitions (files untouched)
shrc refresh # re-scan and sync the manifest with the files
shrc version
shrc helpeval "$(shrc set EDITOR vim)"
eval "$(shrc rm EDITOR)"# bash / zsh / POSIX sh
shrc() {
case "$1" in
set|rm|remove|unset|delete)
eval "$(command shrc "$@")"
;;
*)
command shrc "$@"
;;
esac
}# fish
function shrc
switch $argv[1]
case set rm remove unset delete
eval (command shrc $argv)
case '*'
command shrc $argv
end
end| Shell | Startup file |
|---|---|
| profile (sh, dash, ...) | ~/.profile |
| bash | ~/.bashrc (or ~/.bash_profile, ~/.bash_login) |
| zsh | ${ZDOTDIR:-$HOME}/.zshrc (or .zprofile, .zshenv) |
| ksh / mksh | ~/.kshrc / ~/.mkshrc |
| fish | ${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish |
| csh / tcsh | ~/.cshrc, ~/.tcshrc, ~/.login |
| nushell | ${XDG_CONFIG_HOME:-$HOME/.config}/nushell/config.nu, env.nu |
| PowerShell | ${XDG_CONFIG_HOME:-$HOME/.config}/powershell/Microsoft.PowerShell_profile.ps1, ~/Documents/PowerShell/... |
| Variable | Effect |
|---|---|
| SHRC_HOME | Where the manifest lives (default: ~/.shrc) |
| SHELL | Picks the syntax of the statement printed for eval |
| XDG_CONFIG_HOME | Base for the fish, nushell and pwsh startup files |
| ZDOTDIR | Directory holding the zsh startup files |
moon check --target native --deny-warn
moon test --target native
moon fmt
moon infopub(all) struct CliResult {
code : Int
out : String
err : String
}pub(all) struct Entry {
kind : EntryKind
name : String
value : String
raw : Bool
list : Bool
imported : Bool
}pub(all) enum EntryKind {
Env
Alias
}pub(all) enum ShellFamily {
Posix
Fish
Csh
Nu
PowerShell
}fn canonical_list(name : String, value : String) -> Stringfn edit_definition_in_text(text : String, family : ShellFamily, name : String, replacement : String?) -> (String, Bool)fn ensure_dir(dir : String) -> Result[Unit, String]fn escape_field(text : String) -> Stringfn home_dir() -> Stringfn install_shell_integration() -> Unitfn is_search_path_name(name : String) -> Boolfn is_valid_alias_name(name : String) -> Boolfn is_valid_env_name(name : String) -> Boolfn manifest_path() -> Stringfn normalize_dir(dir : String) -> Stringfn path_dirname(path : String) -> Stringfn path_insert(value : String, dir : String, at_end : Bool) -> Stringfn path_join(left : String, right : String) -> Stringfn path_remove(value : String, dir : String) -> (String, Bool)fn quote_csh(value : String) -> Stringfn quote_csh_live(value : String) -> Stringfn quote_fish(value : String) -> Stringfn quote_fish_live(value : String) -> Stringfn quote_nu(value : String) -> Stringfn quote_nu_live(value : String) -> Stringfn quote_posix(value : String) -> Stringfn quote_posix_live(value : String) -> Stringfn quote_ps(value : String) -> Stringfn quote_ps_live(value : String) -> Stringfn refs_translatable(text : String) -> Boolfn same_dir(a : String, b : String) -> Boolfn self_ref(name : String) -> Stringfn shrc_home() -> Stringlet shrc_version : Stringfn xdg_config_home() -> StringInstall
Download zipManage environment variables and aliases across bash, zsh, fish and other shells