Showing posts with label fish-shell. Show all posts
Showing posts with label fish-shell. Show all posts

Wednesday, December 2, 2015

hstr (hh) and fish

Thanks again to the team at the Ubuntu podcast and their listeners I'm trying out hstr, but unlike Martin, didn't want to switch from fish back to bash, so...

The proper way to do this would be to modify hstr to support the fish history file format, but I wanted to try it out a bit before putting the effort in (if I ever get around to it).

The following steps provide a poor man's port by forcing fish to maintain a bash compatible history file (in addition to fish's own history) and pointing hstr to it:

1. Modify your fish prompt to save the bash compatible history file:

~/.config/fish/functions/fish_prompt.fish:

function fish_prompt
    .
    .
    .
    echo $history[1] | grep -Ev '(^hh$|^sd|^l.$)' >> ~/.config/fish/hh.history
end


The command as written above filters out the hh command itself, my version of cd, sd, and directory list commands such as ls, ll, lh, etc.


2. Set HISTFILE in config.fish:

~/.config/fish/config.fish:

set -x HISTFILE ~/.config/fish/hh.history

If you want your existing fish history to be available immediately, use Martin's command line love from S08E32:

grep cmd ~/.config/fish/fish_history | cut -d' ' -f3- | sort -u >> ~/.bash_history

Alternatively you could just point HISTFILE to ~/.bash_history.

Sunday, January 18, 2015

Guake and Fish

With many thanks to Alan Pope via the Ubuntu UK Podcast I've switched my terminal environment from the standard gnome-terminal with bash to Guake and fish.

Guake suits my workflow as I like to have applications in separate workspaces and switch between the terminal and application.  Guake, which gets its name and style of operation from early first-person-shooter games such as Quake (except it's for Gnome, get it? :-)) is easily accessible via a hotkey - F12 by default - and will always display in the current workspace.

To learn more, see:

* https://github.com/Guake/guake - the official repository
* http://dalibornasevic.com/posts/48-guake-terminal-for-super-productivity - provides some useful configuration tips

To install and automatically start at logon in Ubuntu 14.04:

sudo apt-get install guake
ln -s /usr/local/share/applications/guake.desktop ~/.config/autostart/guake.desktop


Fish - the Friendly Interactive Shell for the 1990's is a step up on bash for two simple reasons:

1. Searching and running previous commands is much more convenient than in bash.  Once can simply type in a part of the command, any part, press the up arrow and step back through commands that contained the search string.

2. While typing a command fish will offer to auto-complete it with what it thinks you want, based on command history and the current directory contents.  You can 1) ignore the offer and type your command in full, 2) press tab to auto-complete in the same manner as bash, or 3) press the right arrow to accept the suggested command, and then Enter to execute the command.

The version that is included in Ubuntu 14.10, lacks two key features that I use: vi style editing and shared history across sessions.

Fortunately, the release currently in development addresses both of these.  To install the nightly build on Ubuntu:

sudo add-apt-repository ppa:fish-shell/nightly-master
sudo apt-get update
sudo apt-get install fish


This, of course, comes with the usual disclaimer that it is still in development and you are likely to encounter bugs.  I haven't had any problems yet, and figure that if something does go drastically wrong I can boot a USB stick and set my shell back to bash until the problem resolves itself.

To learn about fish, simply type help at the prompt and a browser window will be opened.

To edit your configuration, type fish_config and once again a browser window will be opened that will allow you to set colours (as the official web page says, you'll have an astonishing 256 colors available for use), modify the prompt, view functions, variables, command history, key bindings and abbreviations.

To enable vi mode and shared history place the following in your config file (~/.config/fish/config.fish):

fish_vi_mode
function fish_prompt
    history --merge  # This enables shared command history across sessions
    fish_vi_prompt
end


Vi mode editing is still a work in progress, and is missing a few features, e.g. replace mode, however, if like me, you only use it for editing particularly long commands it will probably be more than adequate.

You can also get a poor man's replace (r) function by adding the following:

bind -m insert r delete-char force-repaint


This simply deletes the character under the cursor and puts the editor into insert mode.  Saves a keystroke sometimes.

Useful links:

* http://fishshell.com/ - the official website
* https://github.com/fish-shell/fish-shell/wiki/Nightly-builds - nightly builds

Enjoy!