I ran across this somewhere on the Internet and have never looked back since: 


function fish_user_key_bindings
  bind \cs 'sudo-my-prompt'
end
function sudo-my-prompt
  set -l cmd (commandline)
  commandline --replace "sudo $cmd"
end

The muscle memory of sudo !! Becomes ctrl-p ctrl-s

It's not exactly the same, but it scratches the same itch. 

Rob

> On May 19, 2016, at 05:04, Mike Costanzo <mrcosta...@gmail.com> wrote:
> 
> I've been using fish for some time now and I understand that the !! syntax is 
> a design decision not an omission.
> That being said, I still miss it all the time.
> 
> So if I want to create a function to fill the 'sudo bang bang void', how 
> would I do it?
> Specifically, how do I pick out the last command from history from a function?
> 
> Thanks,
> 
> -Mike
> 
>  
> 
>> On Thu, May 19, 2016 at 4:47 AM, Mike Meyer <m...@mired.org> wrote:
>> !$ is spelled Alt-UpArrow (or similar, depending on how your 
>> keyboard/windowing system/etc. is configured). 
>> 
>> For !!, just use history and edit. With Emacs bindings, it's C-P C-A "sudo 
>> ". Not quite as convenient in general, though in this case similar. But it's 
>> obvious if you just think about it as editing history.
>> 
>>> On Thu, May 19, 2016 at 3:41 AM Stig Brautaset <s...@brautaset.org> wrote:
>>> Hello!
>>> 
>>> I'm a recent migrant from zsh and overall I'm overall happy with fish,
>>> but I do sorely miss the !$ and !! constructs. As an example, I often
>>> type a command only to have it error because I forgot to precede it with
>>> sudo. In zsh I would normally just type "sudo !!" to execute the
>>> previous command again, properly prefixed with sudo.
>>> 
>>> I understand that !$ and !! are not super discoverable, and that this is
>>> an explicit design goal in fish. Does fish have an alternative mechanism
>>> for this case that I just haven't discovered yet because I'm not
>>> thinking outside my zsh-shaped box? All suggestions welcome.
>>> 
>>> Stig
>>> 
>>> 
>>> ------------------------------------------------------------------------------
>>> Mobile security can be enabling, not merely restricting. Employees who
>>> bring their own devices (BYOD) to work are irked by the imposition of MDM
>>> restrictions. Mobile Device Manager Plus allows you to control only the
>>> apps on BYO-devices by containerizing them, leaving personal data untouched!
>>> https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
>>> _______________________________________________
>>> Fish-users mailing list
>>> Fish-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/fish-users
>> 
>> ------------------------------------------------------------------------------
>> Mobile security can be enabling, not merely restricting. Employees who
>> bring their own devices (BYOD) to work are irked by the imposition of MDM
>> restrictions. Mobile Device Manager Plus allows you to control only the
>> apps on BYO-devices by containerizing them, leaving personal data untouched!
>> https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
>> _______________________________________________
>> Fish-users mailing list
>> Fish-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/fish-users
> 
> ------------------------------------------------------------------------------
> Mobile security can be enabling, not merely restricting. Employees who
> bring their own devices (BYOD) to work are irked by the imposition of MDM
> restrictions. Mobile Device Manager Plus allows you to control only the
> apps on BYO-devices by containerizing them, leaving personal data untouched!
> https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
> _______________________________________________
> Fish-users mailing list
> Fish-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/fish-users
------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to