You are not logged in.
Pages: 1
Topic closed
I have been googling for a solution in last few hours to no avail. I think I'm missing something very simple here.
I'm using Fish shell, which use functions rather than alias like bash does.
So, I have a function that alias vi to vim which works just fine!
function vi
vim $argv
endAlthough when I type 'sudo vi' it doesn't run through fish functions and defer to vi instead of vim...
I've tried to make system wide function in /usr/share/fish/functions but that doesn't work either. Only thing I can find is this http://askubuntu.com/questions/22037/al … using-sudo but it is for bash only.
Or maybe this isn't meant to be. If so, please let me know and possibly an explanation why sudo work that way (or link me to reference if possible). Thanks in advance!
Last edited by chestlick (2015-03-23 00:23:02)
Offline
The Bash fix doesn't work? What about if you use the built in Fish alias likeso:
alias sudo "sudo "If that doesn't work, you can always make another alias:
function svi
sudo vim $argv
endthat would be quicker than typing out sudo anyway.
EDIT: And, if you insist on writing out "sudo vi" you have:
function sudo vi
sudo vim $argv
endLast edited by nullified (2015-03-23 00:02:34)
"We may say most aptly, that the Analytical Engine weaves algebraical patterns just as the Jacquard-loom weaves flowers and leaves." - Ada Lovelace
Offline
You could also just drop a symlink 'vi' that points to vim somewhere in your path.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Where are you placing these functions? bash has a system-wide config and per-user configs. Have you tried setting up a config for root?
Offline
You could also just drop a symlink 'vi' that points to vim somewhere in your path.
Thinking smarter not harder! Good point.
There is a discussion here I found with some info. about the interaction between Fish and sudo: http://comments.gmane.org/gmane.comp.sh … .user/1933
"We may say most aptly, that the Analytical Engine weaves algebraical patterns just as the Jacquard-loom weaves flowers and leaves." - Ada Lovelace
Offline
alias sudo "sudo " doesn't work here for me.
Yeah. I thought about creating a function like that.
I guess I just wanted to know why none of fish functions get passed to sudo command.
If that's the case, then I will probably have to add sudo to several of my functions, or figure something out.
Offline
Where are you placing these functions? bash has a system-wide config and per-user configs. Have you tried setting up a config for root?
I tried all of the three places, ~/.config/fish/functions/, /usr/share/fish/functions/, and /etc/fish/functions/. No avail with sudo vi.
Setting up a config for root? You mean as setting up fish functions for the root itself, /root/.config/fish/functions/? Yes, I did that too. For some reason it doesn't work when I do sudo either.
Offline
This is not specific to fish. That's why a workaround is needed for bash as well.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Yeah. For some reason I just realized that. Bash sudo doesn't work with aliases as well.
At least I learned something today. Felt like I wasted your time. Sorry!\
Thanks for fast responses!
Last edited by chestlick (2015-03-23 00:21:17)
Offline
I should maybe not necrobump this old thread marked SOLVED, but none of the solutions solved similar issue.
What I ended up doing:
function vi
command vim
end
function sudo
switch $argv[1]
case vi
command sudo vim $argv[2..-1]
case '*'
command sudo $argv
end
endMore functionality can be added.
Last edited by MDykstra (2026-11-25 22:38:34)
Offline
That seems to drop the sudo for "sudo vi" and also nobody here should under no circumstances use sudo vim anyway, but sudoedit
Offline
Darn, made a typo:
command vim $argv[2..-1]should be:
command sudo vim $argv[2..-1]My own issue wasn't with vi or vim, but used it to align with the thread content.
Know about sudoedit and visudo, but non the less I use sudo vim.
Anyway it solved my issue.
Offline
I should maybe not necrobump this old thread marked SOLVED [...]
Mod note: No, you shouldn't. Closing.
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
Pages: 1
Topic closed