Thi's avatar
HomeAboutNotesBlogTopicsToolsReading
About|My sketches |Cooking |Cafe icon Support Thi
πŸ’Œ [email protected]

Terminal + ZSH

Anh-Thi Dinh
SkillsLinuxData EngineeringTools
Left aside
A collection of console terminals in serveral operation systems.
πŸ‘‰Β Note:

No need to remember commands using AI

I’m using Claude Code, if you use another Coding CLI service, modify the codes. Insert below codes in .bashrc or .zshrc and then source ~/.zshrc:

Useful shortcuts with texts in the terminal

Only for macOS (Windows/Linux isn’t checked yet)

Terminals

Windows

Install cmder (drop-down by Ctr + \) and I use this personal setting files.
πŸ‘‰ Note: WSL on Windows

Linux

  • Download guake terminal
  • Install Zsh, check the previous section.

MacOS

πŸ‘‰ Using iTerms2. Download its settings.

Remember the last command lines for each project

Zsh

(MacOS) Install Homebrew first.
πŸ‘‰Β Note: WSL on Windows

Install Zsh + oh-my-zsh

On MacOS, Zsh is already installed and default.
Install oh-my-zsh.

Plugins

Install below plugins (using oh-my-zsh way) first:
  • zsh-autosuggestions
  • zsh-syntax-highlighting
After installing plugins, put them in ~/.zshrc

spaceship-prompt theme

Install using oh-my-zsh way: check here:
Set ZSH_THEME="spaceship" in your .zshrc.

Fonts

Install font Source Code Pro:
  1. Install wget and fontconfig first using brew
  1. Follow instruction here (step 1-4). If some folders don't exist, create them!
  1. Install Source Code Pro for Powerline and then
Powerline font,
In terminal, choose the corresponding installed fonts.
Add alias to ~/.zshrc (search "alias" to find the place to put).

Display execution time below to command

The following tip will display the execution time of a command. This can be useful, especially when you execute the same command multiple times and need to know when the last command was executed.

Other plugins

  1. fzf -- search in terminal. (Use: fzf)
Β 
β—†Useful shortcuts with texts in the terminalβ—†Terminalsβ—‹Windowsβ—‹Linuxβ—‹MacOSβ—†Remember the last command lines for each projectβ—†Zshβ—‹Install Zsh + oh-my-zshβ—‹Pluginsβ—‹spaceship-prompt themeβ—‹Fontsβ—‹Display execution time below to commandβ—†Other plugins
About|My sketches |Cooking |Cafe icon Support Thi
πŸ’Œ [email protected]
1claude_execute() {
2  emulate -L zsh
3  setopt NO_GLOB
4  local query="$*"
5  local prompt="You are a command line expert. The user wants to run a command but they don't know how. Here is what they asked: ${query}. Return ONLY the exact shell command needed. Do not prepend with an explanation, no markdown, no code blocks - just return the raw command you think will solve their query."
6  local cmd
7  # use Claude Code
8  cmd=$(claude --dangerously-skip-permissions --disallowedTools "Bash(*)" --model default -p "$prompt" --output-format text | tr -d '\000-\037' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
9  if [[ -z "$cmd" ]]; then
10    echo "claude_execute: No command found"
11    return 1
12  fi
13  echo -e "$ \033[0;36m$cmd\033[0m"
14  eval "$cmd"
15}
16alias ask="noglob claude_execute"
1# Usage
2ask "List all conda env in this computer"
1Ctrl+A # go to the beginning of line
2Ctrl+E # go to the end of line
3Ctrl+R # search prompt history
4Option+Left # back one word
5Option+Right # forward one word
6Ctrl+U # remove the entire line containing the cursor
7Ctrl+K # delete from cursor to end of line
8Crtl+W # delete a word backward (left of cursor)
9Alt+D # delete a word forward (right of cursor)
1# check is installed
2zsh --version
1# install (linux)
2sudo apt install zsh
3
4# install (macos - integrated)
1# make zsh default bash
2chsh -s $(which zsh) # log out & log in
1# check
2echo $SHELL # /bin/zsh  or similar
1plugins=(git docker docker-compose zsh-syntax-highlighting dnf npm)
2# for me
3# plugins=(git docker docker-compose npm ruby python emoji)
1brew install wget
2brew install fontconfig
1fc-cache -f -v
1sudo apt-get install fonts-powerline
1# Push below in .zshrc
2preexec () {
3  local TIME=`date +"[%H:%M:%S] "`
4  local zero='%([BSUbfksu]|([FK]|){*})'
5  local PROMPTLEN=${#${(S%%)PROMPT//$~zero/}}
6  echo "\033[1A\033[$(($(echo -n $1 | wc -m)+$PROMPTLEN))C $fg[blue]${TIME}$reset_color"
7}