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

3
4
5
6
7
8
9
10
11
12
13
14
#
# No plugin manager is needed to use this file. All that is needed is adding:
#   source {where-znt-is}/zsh-navigation-tools.plugin.zsh
#
# to ~/.zshrc.
#

# According to the standard:
# http://zdharma.org/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
0="${${(M)0:#/*}:-$PWD/$0}"
export ZNT_REPO_DIR="${0:h}"
psprint's avatar
psprint committed
15
export ZNT_CONFIG_DIR="$HOME/.config/znt"
16

17
18
19
20
21
22
23
24
25
26
27
#
# Update FPATH if:
# 1. Not loading with a plugin manager
# 2. Not having fpath already updated
#

if [[ ${zsh_loaded_plugins[-1]} != */zsh-navigation-tools && -z ${fpath[(r)${0:h}]} ]]
then
    fpath+=( "${0:h}" )
fi

28
29
30
31
#
# Copy configs
#

psprint's avatar
psprint committed
32
33
if [[ ! -d "$HOME/.config" ]]; then
    command mkdir "$HOME/.config"
34
35
fi

psprint's avatar
psprint committed
36
37
if [[ ! -d "$ZNT_CONFIG_DIR" ]]; then
    command mkdir "$ZNT_CONFIG_DIR"
38
39
fi

Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
40
# 9 files
psprint's avatar
psprint committed
41
42
43
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
44

Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
45
46
# Check for random 2 files if they exist
# This will shift 0 - 7 elements
psprint's avatar
psprint committed
47
48
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
49
    # Something changed - examine every file
psprint's avatar
psprint committed
50
51
52
53
54
55
    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
56
57
        fi
    done
psprint's avatar
psprint committed
58
    unset __ZNT_CONFIG_FILE
Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
59
fi
60

psprint's avatar
psprint committed
61
unset __ZNT_CONFIG_FILES
62

63
64
65
66
#
# Load functions
#

Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
67
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
68
69
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
70
alias nkill=n-kill noptions=n-options npanelize=n-panelize nhelp=n-help
71
72
73
74

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
75
zstyle ':completion::complete:n-kill::bits' matcher 'r:|=** l:|=*'
76