]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/zsh-navigation-tools/zsh-navigation-tools.plugin.zsh
54c819810de514e5a4ecce3e3e8a2016daf55b63
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / zsh-navigation-tools / zsh-navigation-tools.plugin.zsh
1 #!/usr/bin/env zsh
2
3 #
4 # No plugin manager is needed to use this file. All that is needed is adding:
5 #   source {where-znt-is}/zsh-navigation-tools.plugin.zsh
6 #
7 # to ~/.zshrc.
8 #
9
10 # According to the standard:
11 # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
12 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
13 0="${${(M)0:#/*}:-$PWD/$0}"
14
15 export ZNT_REPO_DIR="${0:h}"
16 export ZNT_CONFIG_DIR="$HOME/.config/znt"
17
18 #
19 # Update FPATH if:
20 # 1. Not loading with a plugin manager
21 # 2. Not having fpath already updated
22 #
23
24 if [[ ${zsh_loaded_plugins[-1]} != */zsh-navigation-tools && -z ${fpath[(r)${0:h}]} ]]
25 then
26     fpath+=( "${0:h}" )
27 fi
28
29 #
30 # Copy configs
31 #
32
33 if [[ ! -d "$HOME/.config" ]]; then
34     command mkdir "$HOME/.config"
35 fi
36
37 if [[ ! -d "$ZNT_CONFIG_DIR" ]]; then
38     command mkdir "$ZNT_CONFIG_DIR"
39 fi
40
41 # 9 files
42 unset __ZNT_CONFIG_FILES
43 typeset -ga __ZNT_CONFIG_FILES
44 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
45
46 # Check for random 2 files if they exist
47 # This will shift 0 - 7 elements
48 shift $(( RANDOM % 8 )) __ZNT_CONFIG_FILES
49 if [[ ! -f "$ZNT_CONFIG_DIR/${__ZNT_CONFIG_FILES[1]}" || ! -f "$ZNT_CONFIG_DIR/${__ZNT_CONFIG_FILES[2]}" ]]; then
50     # Something changed - examine every file
51     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
52     unset __ZNT_CONFIG_FILE
53     typeset -g __ZNT_CONFIG_FILE
54     for __ZNT_CONFIG_FILE in "${__ZNT_CONFIG_FILES[@]}"; do
55         if [[ ! -f "$ZNT_CONFIG_DIR/$__ZNT_CONFIG_FILE" ]]; then
56             command cp "$ZNT_REPO_DIR/.config/znt/$__ZNT_CONFIG_FILE" "$ZNT_CONFIG_DIR"
57         fi
58     done
59     unset __ZNT_CONFIG_FILE
60 fi
61
62 unset __ZNT_CONFIG_FILES
63
64 #
65 # Load functions
66 #
67
68 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
69 autoload znt-usetty-wrapper znt-history-widget znt-cd-widget znt-kill-widget
70 alias naliases=n-aliases ncd=n-cd nenv=n-env nfunctions=n-functions nhistory=n-history
71 alias nkill=n-kill noptions=n-options npanelize=n-panelize nhelp=n-help
72
73 zle -N znt-history-widget
74 bindkey '^R' znt-history-widget
75 setopt AUTO_PUSHD HIST_IGNORE_DUPS PUSHD_IGNORE_DUPS
76 zstyle ':completion::complete:n-kill::bits' matcher 'r:|=** l:|=*'
77