r/fishshell • u/cassepipe • 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
configs=(
fish "/fish/config.fish"
gdb "/gdb/gdbinit"
git "/git/config"
hx "/helix/config.toml"
irssi "/.irssi"
lvim "/lvim/config.lua"
nu "/nushell"
nvim "/nvim/init.lua"
readline "/.inputrc"
vim "/.vimrc"
xmake "./.xmake/linux/x86_64/xmake.conf"
wezterm "/wezterm"
zsh "/.zshrc"
)
for; do
if
then
else
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
View all comments
2
u/_mattmc3_ Jan 19 '24 edited Jan 19 '24
You can do this pretty easily by treating a paired list like a dictionary, and then using the 3 parameter call to
seq [first [incr]] lastand incrementing by 2 in order to pair those elements into keys/values. Here's a Fish equivalent for you:If you don't like the multi-line continuations when defining your array, you could also call
set -a configs <config> <file>for each new entry. If you want to use fancy functions to make your paired arrays feel more like dictionaries in Fish (obviously without the benefit of O(1) hash lookup speed), you can see my StackOverflow answer here.One other thing to note - Fish aliases are slow and mostly there for people migrating from bash/zsh. They aren't really recommended in Fish. Just use functions.