A collection of console terminals in serveral operation systems.
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: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"Only for macOS (Windows/Linux isn’t checked yet)
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)👉 Note: WSL on Windows
- Install Zsh, check the previous section.
👉 Using iTerms2. Download its settings.
Remember the last command lines for each project
(MacOS) Install Homebrew first.
👉 Note: WSL on Windows
On MacOS, Zsh is already installed and default.
1# check is installed
2zsh --version1# install (linux)
2sudo apt install zsh
3
4# install (macos - integrated)1# make zsh default bash
2chsh -s $(which zsh) # log out & log in1# check
2echo $SHELL # /bin/zsh or similarInstall oh-my-zsh.
Install below plugins (using oh-my-zsh way) first:
After installing plugins, put them in
~/.zshrc1plugins=(git docker docker-compose zsh-syntax-highlighting dnf npm)
2# for me
3# plugins=(git docker docker-compose npm ruby python emoji)Install using oh-my-zsh way: check here:
Set
ZSH_THEME="spaceship" in your .zshrc.Install font Source Code Pro:
- Install
wgetandfontconfigfirst using brew
1brew install wget
2brew install fontconfig- Follow instruction here (step 1-4). If some folders don't exist, create them!
- Install Source Code Pro for Powerline and then
1fc-cache -f -vPowerline font,
1sudo apt-get install fonts-powerlineIn terminal, choose the corresponding installed fonts.
Add alias to
~/.zshrc (search "alias" to find the place to put).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.
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}- fzf -- search in terminal. (Use:
fzf)