zsh-navigation-tools.plugin.zsh
2386 bytes
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
120="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
130="${${(M)0:#/*}:-$PWD/$0}"
14
15export ZNT_REPO_DIR="${0:h}"
16export 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
24if [[ ${zsh_loaded_plugins[-1]} != */zsh-navigation-tools && -z ${fpath[(r)${0:h}]} ]]
25then
26 fpath+=( "${0:h}" )
27fi
28
29#
30# Copy configs
31#
32
33if [[ ! -d "$HOME/.config" ]]; then
34 command mkdir "$HOME/.config"
35fi
36
37if [[ ! -d "$ZNT_CONFIG_DIR" ]]; then
38 command mkdir "$ZNT_CONFIG_DIR"
39fi
40
41# 9 files
42unset __ZNT_CONFIG_FILES
43typeset -ga __ZNT_CONFIG_FILES
44set +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
48shift $(( RANDOM % 8 )) __ZNT_CONFIG_FILES
49if [[ ! -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
60fi
61
62unset __ZNT_CONFIG_FILES
63
64#
65# Load functions
66#
67
68autoload 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
69autoload znt-usetty-wrapper znt-history-widget znt-cd-widget znt-kill-widget
70alias naliases=n-aliases ncd=n-cd nenv=n-env nfunctions=n-functions nhistory=n-history
71alias nkill=n-kill noptions=n-options npanelize=n-panelize nhelp=n-help
72
73zle -N znt-history-widget
74bindkey '^R' znt-history-widget
75setopt AUTO_PUSHD HIST_IGNORE_DUPS PUSHD_IGNORE_DUPS
76zstyle ':completion::complete:n-kill::bits' matcher 'r:|=** l:|=*'
77