zsh-navigation-tools.plugin.zsh 1.84 KB
Newer Older
1
2
#!/usr/bin/env zsh

psprint's avatar
psprint committed
3
4
5
0="${(%):-%N}" # this gives immunity to functionargzero being unset
export ZNT_REPO_DIR="${0%/*}"
export ZNT_CONFIG_DIR="$HOME/.config/znt"
6
7
8
9
10

#
# Copy configs
#

psprint's avatar
psprint committed
11
12
if [[ ! -d "$HOME/.config" ]]; then
    command mkdir "$HOME/.config"
13
14
fi

psprint's avatar
psprint committed
15
16
if [[ ! -d "$ZNT_CONFIG_DIR" ]]; then
    command mkdir "$ZNT_CONFIG_DIR"
17
18
fi

Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
19
# 9 files
psprint's avatar
psprint committed
20
21
22
unset __ZNT_CONFIG_FILES
typeset -ga __ZNT_CONFIG_FILES
set +A __ZNT_CONFIG_FILES n-aliases.conf n-env.conf n-history.conf n-list.conf n-panelize.conf n-cd.conf n-functions.conf n-kill.conf n-options.conf
23

Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
24
25
# Check for random 2 files if they exist
# This will shift 0 - 7 elements
psprint's avatar
psprint committed
26
27
shift $(( RANDOM % 8 )) __ZNT_CONFIG_FILES
if [[ ! -f "$ZNT_CONFIG_DIR/${__ZNT_CONFIG_FILES[1]}" || ! -f "$ZNT_CONFIG_DIR/${__ZNT_CONFIG_FILES[2]}" ]]; then
Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
28
    # Something changed - examine every file
psprint's avatar
psprint committed
29
30
31
32
33
34
    set +A __ZNT_CONFIG_FILES n-aliases.conf n-env.conf n-history.conf n-list.conf n-panelize.conf n-cd.conf n-functions.conf n-kill.conf n-options.conf
    unset __ZNT_CONFIG_FILE
    typeset -g __ZNT_CONFIG_FILE
    for __ZNT_CONFIG_FILE in "${__ZNT_CONFIG_FILES[@]}"; do
        if [[ ! -f "$ZNT_CONFIG_DIR/$__ZNT_CONFIG_FILE" ]]; then
            command cp "$ZNT_REPO_DIR/.config/znt/$__ZNT_CONFIG_FILE" "$ZNT_CONFIG_DIR"
Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
35
36
        fi
    done
psprint's avatar
psprint committed
37
    unset __ZNT_CONFIG_FILE
Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
38
fi
39

psprint's avatar
psprint committed
40
unset __ZNT_CONFIG_FILES
41

42
43
44
45
#
# Load functions
#

Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
46
autoload n-aliases n-cd n-env n-functions n-history n-kill n-list n-list-draw n-list-input n-options n-panelize n-help
47
48
autoload znt-usetty-wrapper znt-history-widget znt-cd-widget znt-kill-widget
alias naliases=n-aliases ncd=n-cd nenv=n-env nfunctions=n-functions nhistory=n-history
Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
49
alias nkill=n-kill noptions=n-options npanelize=n-panelize nhelp=n-help
50
51
52
53

zle -N znt-history-widget
bindkey '^R' znt-history-widget
setopt AUTO_PUSHD HIST_IGNORE_DUPS PUSHD_IGNORE_DUPS
Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
54
zstyle ':completion::complete:n-kill::bits' matcher 'r:|=** l:|=*'
55