• prezto is my preferred zsh framework.

Links

Add jog (previous commands in the directory) functionality to zsh with zsh-histdbhacks

 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 in zshhacks

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.

Startup order

There are system wide configs (/etc) and user specific (home directory):

filewhen
/etc/zshenvalways
~/.zshenvusually
/etc/zprofilelogin
~/.zprofilelogin
/etc/zshrcinteractive
.zshrcinteractive
/etc/zloginlogin

PATH and macOS load order

macOS has a path helper (/usr/libexec/path_helper) that is run in etc/zprofile which will modify PATH setup up that point. This means that ~/.zshenv may end up clobbered. The recommended cure is to place PATH modifications in ~/.zshrc. Unfortunately this runs counter to other advice you may receive. For example, at one point spacemacs asked for PATH configuration in ~.zshenv. Ultimately you may need to manage some path work in both places depending on the problem being solved, and /etc/paths(.d) is an alternative (but apparently macOS specific).