├── LICENSE ├── README.md ├── completions └── sudo.fish └── functions ├── __ethp_commandline_toggle_sudo.fish └── sudo.fish /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Ethan P. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Improved Sudo for Fish Shell 2 | 3 | An improved `sudo` command for fish shell. 4 | 5 | 6 | 7 | ## Features 8 | 9 | **Enter a superuser shell with a single word.** 10 | No fiddling with environment variables or having to type `sudo fish`. 11 | Just type `sudo` and press enter! 12 | 13 | ```fish 14 | sudo 15 | ``` 16 | 17 | **Press CTRL+S to toggle between a sudo and non-sudo command.** 18 | One of the most convenient features of bash is the `sudo !!` substitution. 19 | While fish may not support `!!`, it can do one better with key bindings. 20 | 21 | If you run a command and find out you need to run it as a superuser, simply press UP and CTRL+S to get that command with the word sudo in front of it. 22 | 23 | ```fish 24 | apt-get update # No permission. 25 | sudo apt-get update # After pressing UP and CTRL+S. 26 | ``` 27 | 28 | 29 | 30 | 31 | ## Install 32 | 33 | With [fisher](https://github.com/jorgebucaran/fisher): 34 | 35 | ```fish 36 | fisher install eth-p/fish-plugin-sudo 37 | ``` 38 | 39 | ### Hotkey Support 40 | 41 | The Ctrl+S hotkey is not added by default. In order to bind the hotkey, add the following to your `config.fish` file: 42 | 43 | ```fish 44 | bind \cs '__ethp_commandline_toggle_sudo.fish' 45 | ``` 46 | 47 | -------------------------------------------------------------------------------- /completions/sudo.fish: -------------------------------------------------------------------------------- 1 | complete -c sudo -d "Better sudo support." 2 | -------------------------------------------------------------------------------- /functions/__ethp_commandline_toggle_sudo.fish: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # A wrapper for sudo that integrates better with the fish shell. 3 | # Copyright (C) 2018,2021 eth-p 4 | # ----------------------------------------------------------------------------- 5 | function __ethp_commandline_toggle_sudo --description 'Toggles sudo on the command line' 6 | set -l buf (commandline -b) 7 | set -l pos (commandline -C) 8 | 9 | if echo "$buf" | grep "^sudo .*\$" 1>/dev/null 2>/dev/null 10 | commandline -r (string sub -s 6 -- "$buf") 11 | commandline -C (math $pos-5) 12 | else 13 | commandline -r "sudo $buf" 14 | commandline -C (math $pos+5) 15 | end 16 | end 17 | 18 | -------------------------------------------------------------------------------- /functions/sudo.fish: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # A wrapper for sudo that integrates better with the fish shell. 3 | # Copyright (C) 2018,2021 eth-p 4 | # ----------------------------------------------------------------------------- 5 | function sudo 6 | env SHELL=(which fish) sudo -sE $argv 7 | end 8 | 9 | --------------------------------------------------------------------------------