summaryrefslogtreecommitdiff
path: root/zsh/functions.zsh
blob: 6003deac05d35ff822869cd6628209f13d926608 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function mpod {
    mcpan pod $1 | $PAGER -c 'set ft=perldoc'
}

function msrc {
    mcpan src $1 | $PAGER -c 'set ft=perl'
}

function scratch {
    local tmp
    tmp=$(mktemp --suffix=.$1)
    vim -c 'set ft='$1 $tmp
    rm $tmp
}

function note {
    local note
    pushd
    cd ~/notes
    note=(${(@f)$(fzf --print-query)})
    if [[ -f $note[2] ]]; then
        $VISUAL $note[2]
    else
        $VISUAL $note[1]
    fi
    popd
}

function fuzzy_history {
    local choice
    choice=($(fc -l 0 | fzf --tac --no-sort))
    [[ $#choice -gt 1 ]] || return
    HISTNO=$(sed 's/[^\d]//g' <<< $choice[1])
    BUFFER=$choice[2,-1]
}

function fuzzy_dirstack {
    local choice
    choice=$(dirs -pl | fzf --tac --no-sort)
    [[ -n $choice ]] && cd $choice
    zle .reset-prompt
}