Skip to content

Instantly share code, notes, and snippets.

@BobCHub
Last active February 14, 2018 08:21
Show Gist options
  • Save BobCHub/67ec106c3372527910fc7eb4d3db3487 to your computer and use it in GitHub Desktop.
Save BobCHub/67ec106c3372527910fc7eb4d3db3487 to your computer and use it in GitHub Desktop.
Zsh and TMUX Set up
################ Z Shell and OH-MY-ZSH #####################
Step 1: Install Updates, Git, and The Z Shell or zsh 
sudo apt-get update
sudo apt-get install zsh
sudo apt-get install git-core
install zsh
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh
- then you change your shell to zsh
chsh -s `which zsh`
- then restart
sudo shutdown -r 0
Step 2: Install Oh-my-zsh - community-driven framework for managing your zsh configuration
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
restart terminal source ~/.zshrc
nano ~/.zshrc //Edit Zsh - Path to your oh-my-zsh configuration
add theme - download theme and place it in your theme directory
change theme - ZSH_THEME=“robbyrussell"
add plugins - download plugin and place it in your plugin directory
add plugins - add plugin name to list in ~/.zshrc config file plugins=(git extract z)
add aliases - add aliases in your ~/.zshrc config file
Examples of Aliases I use
alias c='clear'
alias r='reset'
alias q=‘exit’
alias l='ls -laFT’
alias pk-install='sudo apt-get install’
alias pk-update='sudo apt-get update’
cd ../.. = ...
cd ../../.. = ....
Directories
~/.oh-my-zsh/themes/  // theme directory
~/.oh-my-zsh/plugins // plugin directory
chsh -s /bin/zsh // Set ZSH as your default shell
source ~/.zshrc // Uptake new changes
upgrade_oh_my_zsh // Upgrade Oh-my-zsh.
########## Best zsh features ###############
Better completion handling. Not only are completions command-specific, Zsh also adds the ability to navigate the completion list by hitting <Tab>
Zsh shows you the possible valid destinations
Hit Tab again allows you to navigate through directories, using Tab or arrow keys. Pressing enter fills in location to command.
More Tab completion
Example
kill r<TAB>
Hit tab and it will give you a keyboard navigable list of commands that start with the letters you typed after kill
Clever history
 <CTRL>+R for performing a recursive search to find a previous command you typed in
Zsh goes one better. You can type part of a command and press <UP>
ie ls <UP>
finds the last command we typed starting with ‘ls’.
What was that switch
Type the start of the switch then press <TAB>.
Example:
ls -<TAB>
lists the switch name with inline documentation. You have the option to use keyboard navigation too.
works on a bafflingly large amount of commands like netstat, git and chmod
spell correction - Did you mean this instead?
Enter part of the name of file/directory case insensitive, hit <TAB> and zsh will autocorrect
take command
Create a new directory and move to it, will create intermediate directories as required.
################# Some of the best Plugins ###########################
Number 1 - z
z - https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/z
Tracks your most used directories, based on ‘frecency’.
Frecency: is a portmanteau of 'recent' and 'frequency'. It is a weighted rank that depends on how often and how recently something occurred. As ar as I know, Mozilla came up with the term.
To z, a directory that has low ranking but has been accessed recently
will quickly have higher rank than a directory accessed frequently a long time ago.
Frecency is determined at runtime.
After a short learning phase, z will take you to the most ‘frecent’ directory that matches ALL of the regexes given on the command line, in order.
##### Number 1 - z
----------------------------------------------------------------------------------------------------------------------------------------
Tmux
Tmux is a terminal multiplexer. . . .
A terminal multiplexer is a software application that can be used to multiplex several virtual consoles, allowing a user to access multiple separate login sessions inside a single terminal window, or detach and reattach sessions from a terminal. It is useful for dealing with multiple programs from a command line interface, and for separating programs from the session of the Unix shell that started the program, particularly so a remote process continues running even when the user is disconnected.
Main Features
Persistence
Similar to VNC, many terminal multiplexers allow the user to start applications from one computer, and then reconnect from a different computer and continue using the same application without having to restart it.
Multiple windows
Multiple terminal sessions can be created, each of which usually runs a single application. The windows are numbered, and the user can use the keyboard to switch between them. Windows can be split-screened.
Session Sharing
Terminal multiplexers allow multiple computers to connect to the same session at once, enabling collaboration between multiple users.
#### Install Tmux ####
sudo apt-get install tmux
#### Using tmux #####
Start a new session
$ tmux
That’s all it takes to launch yourself into a tmux session.
Reference
Cheat sheet:
Launching a command:
Ctrl+b <command>
NOTE: First press together keyboard keys Ctrl and b buttons. Then release your fingers from then and press b. Do not laugh, a lot of people don't get it right. ;)
Commands
Windows:
c - window: create
, - window: rename
p - window: previous
n - window: next
w - window: select available windows
s - window: list all sessions
Splits:
% - Split: Vertical
" - Split: Horizontal
Misc
: - Commands: Run a custom named command which you have created (e.g. "split-windows")
Panes:
q - Pane: Show numbers
x - Pane: Kill
o - Panes: Swap
Swapping between panes:
Once you have already split your window to few panes, you can move between them via the arrow buttons ←, ↑, → and ↓
Example: Ctrl+b and then ↑ will move you to the pane above the current one.
Sessions:
tmux new -s session-name
tmux list-sessions
tmux attach -t session-name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment