You are not logged in.

#1 2015-03-22 23:49:37

chestlick
Member
Registered: 2015-03-22
Posts: 4

[SOLVED] At wit's end with fish shell functions and sudo

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
end

Although 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

#2 2015-03-22 23:59:00

nullified
Member
From: Massachusetts, USA
Registered: 2013-12-09
Posts: 468

Re: [SOLVED] At wit's end with fish shell functions and sudo

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
end

that 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
end

Last 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

#3 2015-03-23 00:09:37

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,566
Website

Re: [SOLVED] At wit's end with fish shell functions and sudo

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

#4 2015-03-23 00:11:43

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] At wit's end with fish shell functions and sudo

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

#5 2015-03-23 00:12:02

nullified
Member
From: Massachusetts, USA
Registered: 2013-12-09
Posts: 468

Re: [SOLVED] At wit's end with fish shell functions and sudo

Trilby wrote:

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

#6 2015-03-23 00:12:15

chestlick
Member
Registered: 2015-03-22
Posts: 4

Re: [SOLVED] At wit's end with fish shell functions and sudo

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

#7 2015-03-23 00:14:20

chestlick
Member
Registered: 2015-03-22
Posts: 4

Re: [SOLVED] At wit's end with fish shell functions and sudo

karol wrote:

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

#8 2015-03-23 00:15:26

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,566
Website

Re: [SOLVED] At wit's end with fish shell functions and sudo

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

#9 2015-03-23 00:20:16

chestlick
Member
Registered: 2015-03-22
Posts: 4

Re: [SOLVED] At wit's end with fish shell functions and sudo

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

#10 2026-11-25 21:59:33

MDykstra
Member
Registered: 2014-03-12
Posts: 13

Re: [SOLVED] At wit's end with fish shell functions and sudo

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
end

More functionality can be added.

Last edited by MDykstra (2026-11-25 22:38:34)

Offline

#11 2026-11-25 22:14:51

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 79,142

Re: [SOLVED] At wit's end with fish shell functions and sudo

That seems to drop the sudo for "sudo vi" and also nobody here should under no circumstances use sudo vim anyway, but sudoedit

Offline

#12 2026-11-25 22:38:16

MDykstra
Member
Registered: 2014-03-12
Posts: 13

Re: [SOLVED] At wit's end with fish shell functions and sudo

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

#13 2026-11-26 06:48:40

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,731
Website

Re: [SOLVED] At wit's end with fish shell functions and sudo

MDykstra wrote:

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

Board footer

Powered by FluxBB