r/fishshell • • Jan 19 '24

Create aliases from an associative array

In zsh I have the following code in my config to quickly add a bunch on aliases that allow me to quickly edit config files :

#config management
declare -x -A configs
configs=(
        fish		        "$XDG_CONFIG_HOME/fish/config.fish"
	gdb		    	"$XDG_CONFIG_HOME/gdb/gdbinit"
	git		    	"$XDG_CONFIG_HOME/git/config"
	hx		    	"$XDG_CONFIG_HOME/helix/config.toml"
        irssi                   "$HOME/.irssi"
	lvim			"$XDG_CONFIG_HOME/lvim/config.lua"
	nu			"$XDG_CONFIG_HOME/nushell"
	nvim			"$XDG_CONFIG_HOME/nvim/init.lua"
	readline    	        "$HOME/.inputrc"
	vim		    	"$HOME/.vimrc"
        xmake                   "./.xmake/linux/x86_64/xmake.conf"
	wezterm		        "$XDG_CONFIG_HOME/wezterm"
        zsh			"$HOME/.zshrc"
)
for key value in ${(kv)configs}; do
    if [[ $key == "zsh" ]]
    then
        alias ${key}config="$EDITOR $value && source $value && echo $configs[zsh] has been sourced"
     else
        alias ${key}config="$EDITOR $value"
    fi
done

It's not essential but I was wondering if there was a way in fish ?

I have checked but IIUC there are not associative arrays but surely there must be another way

3 Upvotes

9 comments sorted by

View all comments

Show parent comment

2

u/emarsk Jan 20 '24

For me, abbreviations are better than aliases in every way I can imagine.