zsh
- prezto is my preferred zsh framework.
- awesome-zsh
- zsh-histdb
Add jog (previous commands in the directory) functionality to zsh with zsh-histdb
jog() {
sqlite3 $HOME/.histdb/zsh-history.db "
SELECT
replace(commands.argv, '
', '
')
FROM commands
JOIN history ON history.command_id = commands.id
JOIN places ON history.place_id = places.id
AND dir = '${PWD}'
AND places.host = '${HOST}'
AND commands.argv != 'jog'
AND commands.argv NOT LIKE 'z %'
AND commands.argv NOT LIKE 'cd %'
AND commands.argv != '..'
ORDER BY start_time DESC
LIMIT 10
"
}
– Source
execute common commands in directory
com() {
eval $(sqlite3 $HOME/.histdb/zsh-history.db "
SELECT
replace(commands.argv, '
', '
')
FROM commands
JOIN history ON history.command_id = commands.id
JOIN places ON history.place_id = places.id
AND dir = '${PWD}'
AND places.host = '${HOST}'
AND commands.argv != 'jog'
AND commands.argv NOT LIKE 'z %'
AND commands.argv NOT LIKE 'cd %'
AND commands.argv != '..'
GROUP BY commands.id
ORDER BY COUNT(commands.id) DESC
LIMIT 10
" | fzf)
}
Add functions directory to zsh
In ~/.zshrc
fpath=( "$DOTFILES_DIR/zsh/functions" "${fpath[@]}" )
autoload -U $fpath[1]/*(.:t)
Scripting
Arrays
Concatenating Arrays1
a=(1 2 3)
b=(4 5 6)
c=($a $b)
echo $c
# => (1 2 3 4 5 6)
Diffing Arrays2
Subtraction
a=(1 2 3)
b=(1 2)
c=${a:|b}
echo $c
# => (3)
Intersection
a=(1 2 3)
b=(1 2)
c=${a:*b}
echo $c
# => (1 2)
Add keyboard shortcuts
bindkey -s '^f' 'git show\n'
The above would run git show
whenever Ctrl+f
is pressed. The flag -s
stands for substitute, i.e. substitute Ctrl+f
for git show and carriage return to execute \n
.