Oh My Fish
by
Scoroncocolo
Recently I wrote about how and why the Command Line shell Fish is so much easier and more fun to work with than either the zsh or Bash shell
The Fish Shell and its OMF plugin are a breeze to install and a lot of fun to fart around with
Follow me like a panther and I'll show you how
"We’re here on Earth to fart around... we’re dancing animals" - Kurt Vonnegut
How Fish Differs from zsh and Bash
The Fish Shell is Way Cooler than ZSH or Bash
Last time I talked about how easy it is to install Fish to replace the default shell on your Terminal app which is probably clunky, hard to configure old zsh if you are using a Mac
Once you have Fish installed it is so easy to switch back to zsh if you don't like Fish
I you are in Fish and you want to go back to zsh just type zsh in the prompt and BAM! You're back running zsh and in the zsh shell just type fish and you're back in the fish shell
If you haven't switched to Fish yet go read my little page on how to change your default terminal shell to Fish and I'l bet I and convince you to give it a try
Installing OMF
To install Oh My Fish (OMF) make sure Fish shell is running and run this in the terminal curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install | fish
The fist thing you will notice once OMF is up and running is that you now have a time stamp on the right edge of your screen
Once OMF is installed on your Fish shell you can run omf theme to see all of the themes available for you to choose from
Probably the most popular the them in Oh My Fish is bobthefish so to run that theme you would type omf install bobthefish
To go back to the original default Fish Shell theme, you need to use the omf theme default command
To find out which theme you are currently running in Oh My Fish (OMF), run the following command in your terminal cat $OMF_CONFIG/theme
To show both installed themes and plugins run omf list
- omf install (package/theme): Installs a specific plugin or theme
- omf list: Lists all currently installed packages and themes
- omf remove (name): Uninstalls a package or theme
- omf help: Displays a full manual for all CLI commands
Straying from the Path
In both the Bash and zsh shell rather than having to enter a long path name to get to a directory/folder, you can set a variable to represent the path to that directory by running DIR1="/Users/stevenhenderson/Desktop/Websites/commandline" for instance so that in order to cd to that directory you simply have to type cd $DIR1 and BAM! you're there
You can do that in the Fish shell too but the syntax is a little different
In fish you would need to run set DIR1 /Users/stevenhenderson/Desktop/Websites/commandline with no equal signs or parenthesis
So now if I wanted a list of all the files in that directory I could run ls $DIR1
You can define the path to yet another directory in Bash by running dir2="/Users/stevenhenderson/Desktop/Websites/fish"> and hit the Enter key or in Fish with set dir2 /Users/stevenhenderson/Desktop/Websites/fish and hit Enter/Return
Now no matter where you are in the Terminal you are you no longer need to use the complete path to cd into or work with files in those two directories/folders because the paths to those folders now have the shortcut/variable $DIR1 and $dir2 (just don't forget to use the dollar sign)
Varible Path in Bosh and zsh
- DIR1="/Users/stevenhenderson/Desktop/Websites/commandline"
- dir2="/Users/stevenhenderson/Desktop/Websites/fish"
Varible Path in Fish
- set DIR1 /Users/stevenhenderson/Desktop/Websites/commandline
- set dir1 /Users/stevenhenderson/Desktop/Websites/fish
This little variable trick works great in all three of the most common Command Line shells - Base zsh and Fish but it is only temporary and once you log out of the current session all three shells "forget" your handy path variables
To make these variables permanent in Bosh and zsh you would need to edit their config files which isn't all that scary of difficult but with Fish you don't have to dig into the guts of the shell
Make Fish Variables Permanent
Universal variables are unique to the fish shell. They are automatically saved and shared across all future shell sessions without you having to modify any configuration files
set -Ux VARIABLE_NAME value
-U makes the variable universal (persistent across reboots)
-x exports it as an environment variable to child processes
set -Ux DIR1 /Users/stevenhenderson/Desktop/Websites/commandline
set -Ux dir1 /Users/stevenhenderson/Desktop/Websites/fish
To quickly move to your Home Directory type cd and the symbol that is called tilde or cd ~
To move quickly to the root directory type cd /
cd .. to go to the parent of your current folder
cd ~ or just cd to jump back to your user’s home directory
cd / to go to the very top of your file system
cd ../.. to move up two levels
cd ../../.. to jump up three levels from your current location
- mkdir Data Makes a new, empty folder/directory named Data
- touch dog.txt Creates a new empty file named dog.txt
- pwd prints the path of the directory you are currently in
- ls lists all files in the current directory/folder
- ls -a list all files including hidden files
- ls -l long listing of all files showing owner, size and time last edited
- ls -R Recursive: Lists everything in the current folder and all subfolders
- ls .. list the contents of the parent directory one level above
- mv oldname.txt newname.txt renames files
- rm filename.txt (remove) permanetly deletes files (caution there be dragons) there is no cmd + Z or undo
- rm -r DeadFolder remove/delete a directory/folder and all of its contents (files and sub-directories) permenatly
- cat AnyFile.txt prints out the entire text of the file
- head AnyFile.txt prints the first 10 lines of specified file
- tail AnyFile.txt prints the last 10 lines of specified file
- echo "Arf! Arf!" > dog.txt replaces any existing text with Arf Arf
- echo "Arf! Arf! Arf!" >> dog.txt adds text below existing text on dog.txt
- cp copies files or folders from one location to another
- say "Everything not forbidden is compulsory" hear your machine speak to you
- say -f filename.txt Reads the contents of a specific text file aloud
- history lists a history of your last 16 (in ZSH/macOS) commands
- history 5 lists your last 5 commands (specify any number you want) and you can use your up arrow to bring them to the command prompt
- open -a "Sublime Text" dog.txt will open the file in Sublime Text (substitute your code editor) if it is installed on your machine
- Command + K Clears the console's screen
- Control + Z to pause a process and put it in the background; you can resume it later with the fg command
General Commands Manual (GCM)
RTFM
In the Terminal type man followed by a command to open the General Commands Manual (GCM) Man Page for that command
So if you wanted to know more about the ls command, you could run the command: man ls and the terminal will spit out everything you could ever want to know about the list command
On General Commands Manual (GCM) Man Pages you use the arrow keys to scroll up and down and the space bar to page down and press the letter "g" to go back to the beginning and shift/g (capitol G) to go to the end
You can search any Man Page by typing a forward slash (/) followed by your search term and hit Enter and the first instance of your term will be shown and highlighted so to see the next instance of your search term press the "n" key
When you are in a Man Page you can press the letter "h" (help) for learning about GCM Man Pages and then type "q" to go back to the Man Page you were on and then "q" again to get back to the Command Line
You can use man to pull up specs on any terminal command except what are called the built-in commands which are commands like cd or jobs or echo all of which have a single Man Page which you can get to by typing man builtins or man builtin and the Enter key
Once you've finished looking through the built-ins Man Page you can type the letter q to quit and go back to the Command Prompt
When you run a man ls or man rm or man (any other) command you'll find that you no longer have the old familiar blinking curser at the end of your prompt instead you'll see the highlighted word END in parenthesis followed by a blinking curser and way to exit the General Commands Manual is to type the letter "q" - no Enter/Return key required and that will take you back to the Command Line
You can also use control + z which will also take you back to the command prompt but that command only suspends the General Commands Manual (GCM) leaving it still running in the background and to go back to the GCM just type fg and BAM! You're back in the manual
Now try this: run the man on any command you want let's say you run man rm and then suspend out of it with control z and run another man command for instance man pwd and then control + z out of that one too
So now you are back to the familiar prompt and you can change directories, copy or delete or move around files working on the Command Line as you normal would but unseen on the console there are still those two processes running in the background
To see those running processes type jobs and hit Return/Enter and the output will be
- [1] - suspended man rm
- [2] + suspended man pwd
To to go to back to the GCM on pwd type fg %2 or run fg %1 to go back to the information on the remove command
If you type just fg with no percent flag the Terminal will output the manual on the last job on the list or the last job you called up on the jobs list
Mouse over the illustration above and you'll see I used the command fgand got output on the last job on the list which was pwd Print Working Directory command and after that I ran fg %3 and got the manual on the mv or move/rename files command
You can have as many instances of the GCM running in the backgorund as you want and this can be very handy when you want to check for instance which flag to use to see hidden files like .git and as the GCM will tell you you can find those hidden files by running li -a
In the illustration above you can see I have four GCM jobs running while I'm working on the command line so if I need to be reminded of which arguments (flags) are needed to output specific information I don't have to leave the Terminal and open up a browser and google around for half an hour when I can just run fg %4 and RTFM on the fourth command on the list
Here's a link to my Command Line page
Scoroncocolo
Thanks for the visit