refactored some stuff

This commit is contained in:
Nikolas Weger 2020-09-06 18:30:19 +02:00
parent d31941c80c
commit b1cbc649cc
11 changed files with 445 additions and 56 deletions

14
install
View file

@ -8,9 +8,15 @@
[[ $1 == "clone" ]] && echo ">>> Cloning needed Repos - Please Wait! <<<"
[[ $1 == "clone" ]] && mkdir -p zsh/plugins
[[ $1 == "clone" ]] && git clone https://github.com/olets/zsh-abbr.git zsh/plugins/abbr
[[ $1 == "clone" ]] && git clone https://github.com/marlonrichert/zsh-autocomplete.git zsh/plugins/autocomplete
[[ $1 == "clone" ]] && git clone https://github.com/larkery/zsh-histdb.git zsh/plugins/histdb
[[ $1 == "clone" ]] && git clone https://github.com/m42e/zsh-histdb-fzf.git zsh/plugins/histdb-fzf
[[ $1 == "clone" ]] && git clone https://github.com/olets/zsh-abbr.git ~/.config/dotfiles/zsh/plugins/abbr
[[ $1 == "clone" ]] && git clone https://github.com/wookayin/fzf-fasd.git ~/.config/dotfiles/zsh/plugins/fzfasd
[[ $1 == "clone" ]] && git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.config/dotfiles/zsh/plugins/syntax
[[ $1 == "clone" ]] && git clone https://github.com/zsh-users/zsh-autosuggestions.git ~/.config/dotfiles/zsh/plugins/suggestions
[[ $1 == "clone" ]] && git clone https://github.com/zsh-users/zsh-completions.git ~/.config/dotfiles/zsh/plugins/completions
[[ $1 == "clone" ]] && git clone https://github.com/urbainvaes/fzf-marks.git ~/.config/dotfiles/zsh/plugins/fzfmarks
[[ $1 == "clone" ]] && git clone https://github.com/voronkovich/gitignore.plugin.zsh.git ~/.config/dotfiles/zsh/plugins/gitignore
[[ $1 == "clone" ]] && git clone https://github.com/reegnz/jq-zsh-plugin.git ~/.config/dotfiles/zsh/plugins/jq
[[ $1 == "clone" ]] && git clone https://github.com/asdf-vm/asdf.git ~/.config/dotfiles/zsh/plugins/asdf
[[ $1 == "clone" ]] && git clone https://github.com/Aloxaf/fzf-tab.git ~/.config/dotfiles/zsh/plugins/fzftab
[[ $1 == "" ]] && echo ">>> Use either 'copy' to copy files or 'clone' to clone needed plugins <<<"

20
zsh/files/asdf.zsh Normal file
View file

@ -0,0 +1,20 @@
# Find where asdf should be installed
ASDF_DIR="${ASDF_DIR:-$ZDOTDIR/plugins/asdf}"
ASDF_COMPLETIONS="$ASDF_DIR/completions"
# If not found, check for Homebrew package
if [[ ! -f "$ASDF_DIR/asdf.sh" || ! -f "$ASDF_COMPLETIONS/asdf.bash" ]] && (( $+commands[brew] )); then
ASDF_DIR="$(brew --prefix asdf)"
ASDF_COMPLETIONS="$ASDF_DIR/etc/bash_completion.d"
fi
# Load command
if [[ -f "$ASDF_DIR/asdf.sh" ]]; then
. "$ASDF_DIR/asdf.sh"
# Load completions
if [[ -f "$ASDF_COMPLETIONS/asdf.bash" ]]; then
. "$ASDF_COMPLETIONS/asdf.bash"
fi
fi

View file

@ -1,7 +1,10 @@
# Ubuntu
[[ -e /etc/zsh_command_not_found ]] && source /etc/zsh_command_not_found
# Arch Linux
[[ -e /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh
# Fedora
if [ -f /usr/libexec/pk-command-not-found ]; then
command_not_found_handler () {
runcnf=1
@ -16,3 +19,16 @@ if [ -f /usr/libexec/pk-command-not-found ]; then
return $retval
}
fi
# OSX Homebrew
# https://github.com/Homebrew/homebrew-command-not-found
if [[ -s '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh' ]]; then
source '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh'
fi
# NixOS
if [ -x /run/current-system/sw/bin/command-not-found ]; then
command_not_found_handler () {
/run/current-system/sw/bin/command-not-found $@
}
fi

View file

@ -1,6 +1,6 @@
zmodload -i zsh/complist
WORDCHARS=''
WORDCHARS='-_'
unsetopt menu_complete
unsetopt flowcontrol
@ -20,8 +20,8 @@ zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path "$HOME/.cache/zsh/compcache/"
zstyle ':completion:*' use-cache yes
zstyle ':completion:*' cache-path "$HOME/.cache/zsh/compcache/"
zstyle ':completion:*:*:*:users' ignored-patterns adm amanda apache at avahi avahi-autoipd backup beaglidx bin bitcoin bitwarden_rs cacti canna clamav ceph colord consul couchdb cups daemon dbus dhcp dhcpcd distcache dnsdist dnsmasq dovecot eeleater elasticsearch fax flatpak flaskdemo ftp games gdm geoclue git gitea gkrellmd gluster gopher gophernicus gnats hacluster haldaemon halt hsqldb http ident irc junkbust kdm kibana landscape ldap lightdm list lldpd logstash lp lxd mail mailman mailnull man mattermost messagebus mldonkey mongodb mxisd mysql nagios named netdata netdump news nfsnobody nm-openvpn nobody nscd ntp nut nvidia-persistenced nweger nx obsrun openvpn operator pcap pcp polkitd pollinate postfix postgres powerdns privoxy proxy pulse prosody puppet pvm quagga radiusd radvd redis rpc rpcuser rpm rtkit root scard sddm shutdown smmsp squid sshd statd stunnel svn synapse sync sys syslog systemd-coredump systemd-journal-remote systemd-network systemd-resolve systemd-timesync tcpdump teamspeak tftp tinyproxy tor transmission tss turnserver usbmux unbound uucp uuidd vault vcsa webvirtmgr wildfly wwwrun www-data xfs youtrack zabbix-agent zabbix-server zabbix zerotier-one zerotier '_*'
@ -35,3 +35,6 @@ zstyle ':completion:*:ssh:*' group-order hosts-domain hosts-host users hosts-ipa
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost megumi _gateway pxm
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*' '*.eeleater.org' '*sublime*' '*.local'
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*'
autoload -U +X bashcompinit
bashcompinit

113
zsh/files/direnv.zsh Normal file
View file

@ -0,0 +1,113 @@
#!/usr/bin/env zsh
#####################
# COMMONS
#####################
autoload colors is-at-least
#########################
# CONSTANT
#########################
BOLD="bold"
NONE="NONE"
#########################
# PLUGIN MAIN
#########################
[[ -z "$DIRENV_HOME" ]] && export DIRENV_HOME="$HOME/.config/direnv"
ZSH_DIRENV_VERSION_FILE=${DIRENV_HOME}/version.txt
#########################
# Functions
#########################
_zsh_direnv_log() {
local font=$1
local color=$2
local msg=$3
if [ $font = $BOLD ]
then
echo $fg_bold[$color] "[zsh-direnv-plugin] $msg" $reset_color
else
echo $fg[$color] "[zsh-direnv-plugin] $msg" $reset_color
fi
}
_zsh_direnv_last_version() {
echo $(curl -s https://api.github.com/repos/direnv/direnv/releases | grep tag_name | head -n 1 | cut -d '"' -f 4)
}
_zsh_direnv_download_install() {
local version=$1
local machine
case "$(uname -m)" in
x86_64)
machine=amd64
;;
i686 | i386)
machine=386
;;
*)
_zsh_direnv_log $BOLD "red" "Machine $(uname -m) not supported by this plugin"
return 1
;;
esac
_zsh_direnv_log $NONE "blue" " -> download and install direnv ${version}"
wget -qc --no-check-certificate https://github.com/direnv/direnv/releases/download/${version}/direnv.${OSTYPE%-*}-${machine} -O "${DIRENV_HOME}/direnv"
chmod +x "${DIRENV_HOME}/direnv"
echo ${version} > ${ZSH_DIRENV_VERSION_FILE}
}
_zsh_direnv_install() {
_zsh_direnv_log $NONE "blue" "#############################################"
_zsh_direnv_log $BOLD "blue" "Installing direnv..."
_zsh_direnv_log $NONE "blue" "-> creating direnv home dir : ${DIRENV_HOME}"
mkdir -p ${DIRENV_HOME} || _zsh_direnv_log $NONE "green" "dir already exist"
local last_version=$(_zsh_direnv_last_version)
_zsh_direnv_log $NONE "blue" "-> retrieve last version of direnv..."
_zsh_direnv_download_install ${last_version}
if [ $? -ne 0 ]
then
_zsh_direnv_log $BOLD "red" "Install KO"
else
_zsh_direnv_log $BOLD "green" "Install OK"
fi
_zsh_direnv_log $NONE "blue" "#############################################"
}
update_zsh_direnv() {
_zsh_direnv_log $NONE "blue" "#############################################"
_zsh_direnv_log $BOLD "blue" "Checking new version of direnv..."
local current_version=$(cat ${ZSH_DIRENV_VERSION_FILE})
local last_version=$(_zsh_direnv_last_version)
if is-at-least ${last_version#v*} ${current_version#v*}
then
_zsh_direnv_log $BOLD "green" "Already up to date, current version : ${current_version}"
else
_zsh_direnv_log $NONE "blue" "-> Updating direnv..."
_zsh_direnv_download_install ${last_version}
_zsh_direnv_log $BOLD "green" "Update OK"
fi
_zsh_direnv_log $NONE "blue" "#############################################"
}
_zsh_direnv_load() {
# export PATH
export PATH=${PATH}:${DIRENV_HOME}
eval "$(direnv hook zsh)"
}
# install direnv if it isnt already installed
[[ ! -f "${ZSH_DIRENV_VERSION_FILE}" ]] && _zsh_direnv_install
# load direnv if it is installed
if [[ -f "${ZSH_DIRENV_VERSION_FILE}" ]]; then
_zsh_direnv_load
fi
unset -f _zsh_direnv_install _zsh_direnv_load

View file

@ -1,21 +1,132 @@
export os=$(grep -E "^ID=" /etc/*release | cut -d= -f2)
#export os=$(grep -E "^ID=" /etc/*release | cut -d= -f2)
fzfComp=""
fzfKeyb=""
#fzfComp=""
#fzfKeyb=""
if [[ $os == "arch" ]]; then
fzfComp="/usr/share/fzf/completion.zsh"
fzfKeyb="/usr/share/fzf/key-bindings.zsh"
#if [[ $os == "arch" ]]; then
# fzfComp="/usr/share/fzf/completion.zsh"
# fzfKeyb="/usr/share/fzf/key-bindings.zsh"
#fi
#if [[ $os == "debian" || $os == "ubuntu" || $os == "kali" ]]; then
# fzfComp="/usr/share/doc/fzf/examples/completion.zsh"
# fzfKeyb="/usr/share/doc/fzf/examples/key-bindings.zsh"
#fi
#if [[ $os == "fedora" ]]; then
# fzfKeyb="/usr/share/fzf/shell/key-bindings.zsh"
#fi
#source $fzfComp &>/dev/null
#source $fzfKeyb &>/dev/null
function setup_using_base_dir() {
# Declare all variables local not no mess with outside env in any way
local fzf_base
local fzf_shell
local fzfdirs
local dir
test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"
if [[ -z "${fzf_base}" ]]; then
fzfdirs=(
"${HOME}/.fzf"
"${HOME}/.nix-profile/share/fzf"
"/usr/local/opt/fzf"
"/usr/share/fzf"
"/usr/local/share/examples/fzf"
)
for dir in ${fzfdirs}; do
if [[ -d "${dir}" ]]; then
fzf_base="${dir}"
break
fi
done
if [[ -z "${fzf_base}" ]]; then
if (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then
if [[ -d "${dir}" ]]; then
fzf_base="${dir}"
fi
fi
fi
fi
if [[ -d "${fzf_base}" ]]; then
# Fix fzf shell directory for Arch Linux, NixOS or Void Linux packages
if [[ ! -d "${fzf_base}/shell" ]]; then
fzf_shell="${fzf_base}"
else
fzf_shell="${fzf_base}/shell"
fi
# Setup fzf binary path
if ! (( ${+commands[fzf]} )) && [[ ! "$PATH" == *$fzf_base/bin* ]]; then
export PATH="$PATH:$fzf_base/bin"
fi
# Auto-completion
if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then
[[ $- == *i* ]] && source "${fzf_shell}/completion.zsh" 2> /dev/null
fi
# Key bindings
if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
source "${fzf_shell}/key-bindings.zsh"
fi
else
return 1
fi
}
function setup_using_debian_package() {
(( $+commands[dpkg] )) && dpkg -s fzf &> /dev/null
if (( $? )); then
# Either not a debian based distro, or no fzf installed. In any case skip ahead
return 1
fi
# NOTE: There is no need to configure PATH for debian package, all binaries
# are installed to /usr/bin by default
# Determine completion file path: first bullseye/sid, then buster/stretch
local completions="/usr/share/doc/fzf/examples/completion.zsh"
[[ -f "$completions" ]] || completions="/usr/share/zsh/vendor-completions/_fzf"
local key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh"
# Auto-completion
if [[ $- == *i* ]] && [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then
source $completions 2> /dev/null
fi
# Key bindings
if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
source $key_bindings
fi
return 0
}
function indicate_error() {
print "[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.\n"\
"Please add \`export FZF_BASE=/path/to/fzf/install/dir\` to your .zshrc" >&2
}
# Check for debian package first, because it easy to short cut
# Indicate to user that fzf installation not found if nothing worked
setup_using_debian_package || setup_using_base_dir || indicate_error
unset -f setup_using_debian_package setup_using_base_dir indicate_error
if [[ -z "$FZF_DEFAULT_COMMAND" ]]; then
if (( $+commands[rg] )); then
export FZF_DEFAULT_COMMAND='rg --files --hidden'
elif (( $+commands[fd] )); then
export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git'
elif (( $+commands[ag] )); then
export FZF_DEFAULT_COMMAND='ag -l --hidden -g ""'
fi
fi
if [[ $os == "debian" || $os == "ubuntu" || $os == "kali" ]]; then
fzfComp="/usr/share/doc/fzf/examples/completion.zsh"
fzfKeyb="/usr/share/doc/fzf/examples/key-bindings.zsh"
fi
if [[ $os == "fedora" ]]; then
fzfKeyb="/usr/share/fzf/shell/key-bindings.zsh"
fi
source $fzfComp &>/dev/null
source $fzfKeyb &>/dev/null

View file

@ -15,13 +15,8 @@ bindkey '\ew' kill-region
bindkey -s '\el' 'ls\n'
bindkey '^r' history-incremental-search-backward
if [[ "${terminfo[kpp]}" != "" ]]; then
bindkey "${terminfo[kpp]}" up-line-or-history
fi
if [[ "${terminfo[knp]}" != "" ]]; then
bindkey "${terminfo[knp]}" down-line-or-history
fi
[[ "${terminfo[kpp]}" != "" ]] && bindkey "${terminfo[kpp]}" up-line-or-history
[[ "${terminfo[knp]}" != "" ]] && bindkey "${terminfo[knp]}" down-line-or-history
if [[ "${terminfo[kcuu1]}" != "" ]]; then
autoload -U up-line-or-beginning-search
@ -35,22 +30,15 @@ if [[ "${terminfo[kcud1]}" != "" ]]; then
bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
fi
if [[ "${terminfo[khome]}" != "" ]]; then
bindkey "${terminfo[khome]}" beginning-of-line
fi
if [[ "${terminfo[kend]}" != "" ]]; then
bindkey "${terminfo[kend]}" end-of-line
fi
[[ "${terminfo[khome]}" != "" ]] && bindkey "${terminfo[khome]}" beginning-of-line
[[ "${terminfo[kend]}" != "" ]] && bindkey "${terminfo[kend]}" end-of-line
bindkey ' ' magic-space
bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word
if [[ "${terminfo[kcbt]}" != "" ]]; then
bindkey "${terminfo[kcbt]}" reverse-menu-complete
fi
[[ "${terminfo[kcbt]}" != "" ]] && bindkey "${terminfo[kcbt]}" reverse-menu-complete
bindkey '^?' backward-delete-char

102
zsh/files/lando.zsh Normal file
View file

@ -0,0 +1,102 @@
#!/usr/bin/env zsh
SITES_DIRECTORY="$HOME/Sites"
CONFIG_FILE="./.lando.yml"
# Enable wp command
function wp() {
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
lando wp "$@"
else
command wp "$@"
fi
}
# Enable composer command
function composer() {
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
lando composer "$@"
else
command composer "$@"
fi
}
# Enable artisan command
function artisan() {
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
lando artisan "$@"
else
command artisan "$@"
fi
}
# Enable yarn command
function yarn() {
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
lando yarn "$@"
else
command yarn "$@"
fi
}
# Enable npm command
function npm() {
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
lando npm "$@"
else
command npm "$@"
fi
}
# Enable gulp command
function gulp() {
if checkForFile $CONFIG_FILE $SITES_DIRECTORY ; then
lando gulp "$@"
else
command gulp "$@"
fi
}
checkForFile() {
local current_directory="$PWD"
# Bash is backwards. 0 is true 1 (non-zero) is false.
flag="1"
# Only bother checking for lando within the Sites directory.
if [[ ":$PWD:" == *":$2"* ]]; then
echo "Checking for file: $1 within $2..."
while true; do
if [ $current_directory != "$2" ]; then
if [ -f "$current_directory/$1" ]; then
return "0"
fi
current_directory="$(dirname $current_directory)"
else
break;
fi
done
if [[ "$flag" == "1" ]]; then
echo "Could not find $1 in the current directory or in any of its parents up to $2."
fi
else
echo "Checking for file: $1"
if [ -f "$1" ]; then
echo "Found it"
return 0
else
echo "Not Found"
return "1"
fi
if [[ "$flag" == "1" ]]; then
echo "Could not find $1."
fi
fi
return $flag
}

20
zsh/files/sudo.zsh Normal file
View file

@ -0,0 +1,20 @@
sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history
if [[ $BUFFER == sudo\ * ]]; then
LBUFFER="${LBUFFER#sudo }"
elif [[ $BUFFER == $EDITOR\ * ]]; then
LBUFFER="${LBUFFER#$EDITOR }"
LBUFFER="sudoedit $LBUFFER"
elif [[ $BUFFER == sudoedit\ * ]]; then
LBUFFER="${LBUFFER#sudoedit }"
LBUFFER="$EDITOR $LBUFFER"
else
LBUFFER="sudo $LBUFFER"
fi
}
zle -N sudo-command-line
# Defined shortcut keys: [Esc] [Esc]
bindkey "\e\e" sudo-command-line
bindkey -M vicmd '\e\e' sudo-command-line

View file

@ -1,7 +0,0 @@
#compdef extract
#autoload
_arguments \
'(-r --remove)'{-r,--remove}'[Remove archive.]' \
"*::archive file:_files -g '(#i)*.(7z|Z|apk|aar|bz2|deb|gz|ipsw|jar|lrz|lz4|lzma|rar|rpm|sublime-package|tar|tar.bz2|tar.gz|tar.lrz|tar.lz|tar.lz4|tar.xz|tar.zma|tar.zst|tbz|tbz2|tgz|tlz|txz|tzst|war|whl|xpi|xz|zip|zst)(-.)'" \
&& return 0

View file

@ -1,25 +1,42 @@
export path=($path $HOME/.config/dotfiles/bin)
export fpath=($fpath $ZDOTDIR/local/fpath)
export fpath=($fpath $ZDOTDIR/plugins/completions/src $ZDOTDIR/local/fpath)
# Completions
mkdir -p $HOME/.cache/zsh
autoload -Uz compinit bashcompinit
autoload -Uz compinit
compinit -d $HOME/.cache/zsh/compdump
bashcompinit
# Own Files
source $ZDOTDIR/files/dircolor.zsh
source $ZDOTDIR/files/aliases.zsh
source $ZDOTDIR/files/completion.zsh
source $ZDOTDIR/files/history.zsh
source $ZDOTDIR/files/keybindings.zsh
source $ZDOTDIR/files/termsupport.zsh
source $ZDOTDIR/files/sudo.zsh
source $ZDOTDIR/files/cnf.zsh
source $ZDOTDIR/files/fzf.zsh
source $ZDOTDIR/files/direnv.zsh
source $ZDOTDIR/files/asdf.zsh
source $ZDOTDIR/files/lando.zsh
# Plugins and Configs
eval "$(fasd --init auto)"
#source $ZDOTDIR/plugins/abbr/zsh-abbr.zsh # need to fix
source $ZDOTDIR/plugins/fzfasd/fzf-fasd.plugin.zsh
export FZF_MARKS_FILE=$HOME/.config/fzfmarks
source $ZDOTDIR/plugins/fzfmarks/fzf-marks.plugin.zsh
source $ZDOTDIR/plugins/gitignore/gitignore.plugin.zsh
source $ZDOTDIR/plugins/jq/jq.plugin.zsh
source $ZDOTDIR/plugins/fzftab/fzf-tab.zsh
source $ZDOTDIR/plugins/suggestions/zsh-autosuggestions.zsh
source $ZDOTDIR/plugins/syntax/zsh-syntax-highlighting.zsh
# Local RC
[[ -f "$ZDOTDIR/local/rc.zsh" ]] && source "$ZDOTDIR/local/rc.zsh"
source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# Theme
export STARSHIP_CONFIG=$ZDOTDIR/starship.toml
eval "$(starship init zsh)"
eval "$(direnv hook zsh)"