aboutsummaryrefslogtreecommitdiffstats
path: root/sh/history-sync.zsh
blob: 586417ff1b850e037cae5fc5ef76135c0483ed6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
mkdir -p $HOME/.cache/vim/hist
function vim {
    local zsh_hist_fname
    zsh_hist_fname=$HOME/.cache/vim/hist/$$
    command vim --cmd "let g:_zsh_hist_fname = '$zsh_hist_fname'" "$@"
    if [[ -r $zsh_hist_fname ]]; then
        while read line; do
            if echo $line | grep -q "[[:space:]']"; then
                line=${line/\'/\'\\\\\'\'}
                line="'$line'"
            fi
            print -s "vim $line"
        done < $zsh_hist_fname
        fc -AI
        rm -f $zsh_hist_fname
    fi
}