Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function make running the previous command as root easier #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@

<br/>

This plugin wraps [Aerys Bat's implementation](https://github.com/fish-shell/fish-shell/wiki/Bash-Style-Command-Substitution-and-Chaining-(!!-!%24-&&-%7C%7C)) of bash style history substitution.
This plugin wraps [Aerys Bat's implementation](https://github.com/fish-shell/fish-shell/wiki/Bash-Style-Command-Substitution-and-Chaining-(!!-!$)) of bash style history substitution.

## Install

```fish
$ omf install bang-bang
$ omf install https://github.com/manos00/plugin-bang-bang
```

## Usage

`!!` on command line will be replaced by last command issued:

```fish
$ mv /etc/hostname /etc/hostname.old
mv: rename /etc/hostname to /etc/hostname.old: Operation not permitted
$ sudo !!
$ cp ~/.dmrc
cp: missing destination file operand
$ !! ~/.dmrc.bak
```

`!$` on command line will be replaced by last command arguments:
Expand All @@ -34,6 +34,14 @@ $ mkdir /tmp/test
$ cd !$
```

`!S` on command line will be replaced by "sudo" plus last command:

```fish
$ mv /etc/hostname /etc/hostname.old
mv: rename /etc/hostname to /etc/hostname.old: Operation not permitted
$ !S
```

## Troubleshooting

If the keybindings fail to work after installing the plugin, the issue is
Expand All @@ -45,13 +53,10 @@ plugin `functions/fish_user_key_bindings.fish` file into it.

# License

[MIT][mit] © [Aerys Bat][aerys-bat], [Derek Stavis][derekstavis] et [al][contributors]
[MIT][mit] © [original creators][contributors] and [me][manos00]


[mit]: http://opensource.org/licenses/MIT
[derekstavis]: http://github.com/derek
[aerys-bat]: https://github.com/AerysBat
[contributors]: https://github.com/derek/plugin-bang-bang/graphs/contributors
[manos00]: https://github.com/manos00
[contributors]: https://github.com/oh-my-fish/plugin-bang-bang/graphs/contributors
[omf-link]: https://www.github.com/oh-my-fish/oh-my-fish

[license-badge]: https://img.shields.io/badge/license-MIT-007EC7.svg?style=flat-square
4 changes: 4 additions & 0 deletions conf.d/plugin-bang-bang.fish
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
bind ! __history_previous_command
bind '$' __history_previous_command_arguments
bind 'S' __history_previous_command_root

# set up the same key bindings for insert mode if using fish_vi_key_bindings
if test "$fish_key_bindings" = 'fish_vi_key_bindings'
bind --mode insert ! __history_previous_command
bind --mode insert '$' __history_previous_command_arguments
bind --mode insert S __history_previous_command_root

end

function _plugin-bang-bang_uninstall --on-event plugin-bang-bang_uninstall
bind --erase --all !
bind --erase --all '$'
bind --erase --all S
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure not do remove all binds here, see #15

Suggested change
bind --erase --all S
bind --erase 'S'

functions --erase _plugin-bang-bang_uninstall
end
8 changes: 8 additions & 0 deletions functions/__history_previous_command_root.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function __history_previous_command_root
switch (commandline -t)
case "!"
commandline -t "sudo $history[1]"; commandline -f repaint
case "*"
commandline -i S
end
end