dideler
6/26/2013 - 2:46 AM

My presentation for @softwareniagara's DevTricks event. My topic was the friendly interactive shell, aka fish. Slides are made with Text

My presentation for @softwareniagara's DevTricks event. My topic was the friendly interactive shell, aka fish.

Slides are made with Text Presentation Program (TPP). View the slides in all their glory using the command tpp fish.tpp.

You can view a recording (that I made at home) here: http://youtu.be/SWmKfb2jQhU

--title The Friendly Interactive Shell (fish)
--author Dennis Ideler | @dideler | ideler.dennis@gmail.com
--date Prepared for Software Niagara's DevTricks | June 25, 2013
--footer dennisideler.com
--## 'today' is a date option, but kinda useless.
--## heading and title seem to do the same thing.
--horline
--##withborder
--fgcolor black
--bgcolor white

--## You can put "pauses" in the page with ---
---

--## colors: red, white, green, blue, cyan, magenta, yellow, black, ...
--## the set color will continue to be used on following slides unless changed
--boldon
--color red
--center Give a man a fish and you feed him for a day
--center Teach a man to fish and you feed him for a lifetime
--boldoff
--color magenta



                                                                      ___
                                                        ___======____=---=)
                                                      /T            \_--===)
                                                      L \ (@)   \~    \_-==)
                                                      \      / )J~~    \-=)
                                                        \\___/  )JJ~~    \)
                                                        \_____/JJJ~~      \
                                                        / \  , \J~~~~      \
                                                        (-\)\=|  \~~~        L__
                                                        (\\)  ( -\)_            ==__
                                                        \V    \-\) ===_____  J\   \\
                                                                \V)     \_) \   JJ J\)
                                                                            /J JT\JJJJ)
                                                                            (JJJ| \UUU)
                                                                            (UU)

--color black

--newpage pg2
--heading Overview

  * A Unix shell that focuses on interactive use, discoverability, and user friendliness
---

  * Released in 2005 by liljencrantz (Axel Liljencrantz)
---

  * Now maintained by ridiculousfish (name unknown; engineer at Apple)
---

  * Hosted at https://github.com/fish-shell/fish-shell
---

  * Official site: http://fishshell.com
---

  * Installation is easy
  
    * Binary packages: .deb & .rpm for Linux, .pkg & .app for OS X

    * Homebrew: brew install fish (OS X)

    * Build from source (tarball or git clone if you want updates)
---

  * Mailing list: https://lists.sourceforge.net/lists/listinfo/fish-users
---

  * IRC: #fish on Freenode (unofficial) or OFTC (official)

--newpage design
--heading Design Philosophy

--center The fish design has three high level goals.

1. Everything that can be done in other shell languages should be possible to do in fish,
   though fish may rely on external commands in doing so.
---

2. Fish should be user friendly, but not at the expense of expressiveness.
   Most tradeoffs between power and ease of use can be avoided with careful design.
---

3. Whenever possible without breaking the above goals, fish should follow the Posix syntax.
---

--## These goals are achieved through the following specific design principles.
--boldon
--ulon
The law of orthogonality
--uloff
--boldoff
The shell language should have a small set of orthogonal features. Any situation where two features are related but not identical, one of them should be removed, and the other should be made powerful and general enough to handle all common use cases of either feature.

--boldon
--ulon
The law of responsiveness
--uloff
--boldoff
The shell should attempt to remain responsive to the user at all times, even in the face of contended or unresponsive filesystems. It is only acceptable to block in response to a user initiated action, such as running a command.

--boldon
--ulon
Configurability is the root of all evil
--uloff
--boldoff
Every configuration option in a program is a place where the program is too stupid to figure out for itself what the user really wants, and should be considered a failure of both the program and the programmer who implemented it.

--boldon
--ulon
The law of user focus
--uloff
--boldoff
When designing a program, one should first think about how to make an intuitive and powerful program. Implementation issues should only be considered once a user interface has been designed.

--boldon
--ulon
The law of discoverability
--uloff
--boldoff
A program should be designed to make its features as easy as possible to discover for the user.

--newpage features
--heading Main Features

--color green
--center "Finally, a command line shell for the 90s"
--color black
---

--beginslideleft
  1. Autosuggestions

  2. Sane Scripting

  3. Man Page Completions

  4. Glorious VGA Colour

  5. Web Based configuration

  6. Works Out Of The Box
--endslideleft

--center I'll go over a few of these

--newpage colour
--heading Glorious VGA Colour

fish natively supports term256, the state of the art in terminal technology.

You'll have an astonishing 256 colors available for use!
---











--beginslidebottom
(•_•)


( •_•)>⌐■-■


(⌐■ _■ )
--endslidebottom

--newpage suggestions
--heading Autosuggestions, Syntax Highlighting, Tab Completions

fish suggests commands as you type, based on history and completions, just like a web browser. Watch out, Netscape Navigator 4.0!
---

syntax highlighting has meaning:
--color red
red = invalid
--color blue
blue = valid
--color black
grey = suggestion
--ulon
Arguments that are valid file paths are also underlined
--uloff

These colours (and many more options) can all be changed.
---

fish knows about options (thanks to man page completions).
Update completions with fish_update_completions.
---

Complete the autosuggestion by hitting the right arrow key.
---

Press tab, and fish will attempt to complete the command, argument, or path.
If there's more than one possibility, it will list them.
Hit tab again to cycle through the possibilities.
---

fish can complete many commands, like git branches (try it, bash vs fish).
---

Syntax highlighting, autosuggestions, and tab completions out of the box, wow!

--newpage scripting
--heading Sane Scripting

fish is fully scriptable, and its syntax is simple, clean, and consistent. 

--beginoutput
function untar --description "Expand/extract tar files"
  set --local ext (echo $argv[1] | awk -F. '{print $NF}')
  switch $ext
    case tar
      tar -xvf $argv[1]
    case gz 
      tar -zxvf $argv[1]
    case bz2
      tar -jxvf $argv[1]
    case '*'
      echo "unknown extension"
  end
end
---

#  Functions can fire on events
function foo --on-event bar; echo 'foo fired'; end
--endoutput
---

--beginshelloutput
$ functions
alias, cd, delete-or-exit, dirh, dirs, down-or-search, eval, export, ...
---
$ functions ls
function ls --description 'List contents of directory'
  command ls -G $argv
end
--endshelloutput
---

Functions go in ~/.config/fish/functions/ (e.g. ~/.config/fish/functions/fish_prompt.fish).

--newpage misc
--heading Cool Stuff

  * Recursive wildcard **
    Search directories recursively
---

e.g.
--beginoutput
alias play-music 'exec mplayer -shuffle -really-quiet ~/Music/**'
--endoutput
---

  * alt+up (instead of !$) to get last part of previous command.
---

e.g.
--beginshelloutput
$ mkdir long-complicated-name
$ cd (alt+up) long-complicated-name
--endshelloutput
---

  * alt+left and alt+right to navigate directory history if prompt is empty.
---

e.g.
--beginshelloutput
$ cd Desktop/stuff
$ (alt+left) pwd
/home/dennis
--endshelloutput
---

  * If the prompt is not empty, alt+left and alt+right jumps over words for quick editing.
    (not possible in bash AFAIK)

--newpage web
--heading Web Based Configuration

For those lucky few with a graphical computer, you can set your colors and view functions, variables, and history all from a web page.

--beginshelloutput
$ fish_config
Web config started at 'http://localhost:8000/'. Hit enter to stop.
Created new window in existing browser session.
--endshelloutput

--newpage help
--heading Getting Help

--beginshelloutput
$ help
shows general help in web browser
---
$ help function
opens help for command in browser
---
$ man function
opens man page for command (content is the same between man and help)
--endshelloutput
---

Of course you can also get help on IRC, StackOverflow, the docs (http://fishshell.com/docs/current) etc.

--newpage
--heading Gotchas and Tips
  
  * Fish purposefully limits the number of "builtins" -- commands that fish includes by default -- in order to maintain simplicity
---

  * e.g. bash has built-in string manipulation
--beginshelloutput
# bash
$ x=file.txt
$ echo ${x%%\.*}
file
---

# fish - use another utility that spawns a new process
$ basename $x .txt
file
--endshelloutput
---

  * fish is non-POSIX compliant
    Considered an advantage by many, not disadvantage; less legacy baggage.
    You don't run into compliance-related issue very often.
---

  * Vim assumes your shell is sh compatible, add `set shell=sh` to your .vimrc
---

  * virtualenv/virtualenvwrapper is said not to work out-of-the-box with fish.
    Try virtualfish.
---

  * To run bash scripts: `bash script.sh` or shebang line or run bash and exit when done.
---

  * All variables in fish are really lists.
---

  * If you're a fan of oh-my-zsh or similar, check out oh-my-fish.

--newpage end

--color magenta
--right   ___======____=-
--right /T            \_-
--right L \ (@)   \~    \
--right  \      / )J~~   
--right   \\___/  )JJ~~  
--right    \_____/JJJ~~  
--right    / \  , \J~~~~ 
--right   (-\)\=|  \~~~  
--right   (\\)  ( -\)_   
--right    \V    \-\) ===
--right           \V)     
--color black

--boldon
--center Fish is fast, the auto-completion is amazingly helpful, and it's intuitive to use without too much configuration.
--center Give it a try!
--boldoff
--color magenta
___
--=)
-===)
_-==)
 \-=)
  \)
    \
     \
      L__
         ==__
_____  J\   \\
 \_) \   JJ J\)
     /J JT\JJJJ)
     (JJJ| \UUU)
      (UU)