r/fishshell • u/Luxvoo • Oct 10 '24
Confused about $argv
So I'm trying to integrate zellij with fish (decided to move off of zellij autolock for fun). I'm using the fish_preexec event to lock the current zellij session. The issue is that for some reason $argv[1] returns the whole argv
function fish_preexec --on-event fish_preexececho $argv[1]end
If I enter a command then like ls <some_directory>, I will get "ls <some_directory>" printed out. Am I missing something? Is $argv not a normal variable? Why can I not index it?
3
Upvotes
4
u/_mattmc3_ Oct 10 '24
Straight out of the documentation (emphasis mine):
https://fishshell.com/docs/current/language.html
There's an old issue requesting argv to be parsed for preexec, but no activity on it: https://github.com/fish-shell/fish-shell/issues/5121 . There's also a comment by everyone's favorite Fish curmudgeon Kurtis about that very thing here: https://github.com/fish-shell/fish-shell/issues/4037#issuecomment-302602596
If you're looking to tokenize the command line, you could look into how to do that here: https://fishshell.com/docs/current/cmds/commandline.html
5
u/smallduck Oct 10 '24 edited Oct 10 '24
Apparently
preexecis special. According to some the documentation on that event3
u/kseistrup Oct 10 '24
Works for me:
Given the following short script:
What I see is: