シェルスクリプト便利コマンドリスト
Zsh Terminal用ショートカットリスト
Appendix-1: ANSI escape sequence
シンボル | 対応コマンド | 説明 |
---|---|---|
^[[ |
ESC + [ |
|
1;5 |
modifier (5 = Ctrl) | |
^A |
Ctrl +A |
|
^G |
Ctrl +G |
ASCII 7, BEL, bell character |
^S |
Ctrl +S |
ASCII 19, XOFF, used for terminal flow control to pause output |
C |
Cursor Right | |
D |
Cursor Left | |
H |
Home key |
Appendix-2: custom keybind setup
以下のファイルを .zshrc
に読み込ませています
custom_keybind.sh
#!/bin/zsh
#---------------------------------------------------
# cursor moving command
#---------------------------------------------------
bindkey '^[[1;5D' backward-word
bindkey '^[[1;5C' forward-word
#---------------------------------------------------
# git-related command
#---------------------------------------------------
function _git_cd() {
echo "cd $(git root)"
cd "$(git root)"
zle accept-line
}
zle -N _git_cd
function _git_status() {
echo "git status -sb"
git status -sb
zle accept-line
#zle reset-prompt
}
zle -N _git_status # _git_status関数をgit_status widgetとして登録
function _git_add() {
echo "git add -u" # promptにgit add -uを表示
git add -u
zle accept-line
}
zle -N _git_add # _git_status関数をgit_status widgetとして登録
function _git_commit_amend() {
echo "git commit --amend --no-edit" # promptにgit commit --amend --no-editを表示
git commit --amend --no-edit
zle accept-line
}
zle -N _git_commit_amend # _git_commit_amend関数をgit_status widgetとして登録
function _git_pull() {
echo "git pull" # promptにgit add -uを表示
git pull
zle accept-line
}
zle -N _git_pull # _git_status関数をgit_status widgetとして登録
function _git_push() {
echo "git push" # promptにgit add -uを表示
git push
zle accept-line
}
zle -N _git_push # _git_status関数をgit_status widgetとして登録
#---------------------------------------------------
# vscode-related command
#---------------------------------------------------
function _vscode_cd() {
echo "code-cd" # promptにgit add -uを表示
code-cd
zle accept-line
}
zle -N _vscode_cd # _git_status関数をgit_status widgetとして登録
#---------------------------------------------------
# bindkey setup
#---------------------------------------------------
# git
bindkey "^G^A" _git_add
bindkey "^G^[[1;5H" _git_cd # Ctrl + g + Home
bindkey "^G^M" _git_commit_amend
bindkey "^G^P" _git_push
bindkey "^G^l" _git_pull
bindkey "^G^S" _git_status
# vscode related
bindkey "^V^[[1;5H" _vscode_cd # Ctrl + v + Home