Add old functionality back again

This commit is contained in:
Marty Oehme 2020-02-01 19:35:54 +01:00
parent c9f0ca46e3
commit b40b6d8c74
7 changed files with 1641 additions and 6 deletions

32
.gitignore vendored
View File

@ -43,7 +43,37 @@ tags
# Coc configuration directory
.vim
# End of https://www.gitignore.io/api/vim,linux
### Zsh ###
# Zsh compiled script + zrecompile backup
*.zwc
*.zwc.old
# Zsh completion-optimization dumpfile
*zcompdump*
# Zsh zcalc history
.zcalc_history
# A popular plugin manager's files
._zplugin
.zplugin_lstupd
# zdharma/zshelldoc tool's files
zsdoc/data
# robbyrussell/oh-my-zsh/plugins/per-directory-history plugin's files
# (when set-up to store the history in the local directory)
.directory_history
# MichaelAquilina/zsh-autoswitch-virtualenv plugin's files
# (for Zsh plugins using Python)
.venv
# Zunit tests' output
/tests/_output/*
!/tests/_output/.gitkeep
# End of https://www.gitignore.io/api/vim,linux,zsh
# Ignore dynamic colorschemes set by styler
colorscheme.vim

View File

@ -0,0 +1,27 @@
#!/bin/sh
# more usage instructions at https://github.com/clvv/fasd
eval "$(fasd --init posix-hook posix_alias bash-hook zsh-hook zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install)"
# eval "$(fasd --init auto)"
alias a='fasd -a' # any
alias s='fasd -si' # show / search / select
# alias d='fasd -d' # directory
# alias f='fasd -f' # file
# alias sd='fasd -sid' # interactive directory selection
# alias sf='fasd -sif' # interactive file selection
alias z='fasd_cd -d' # cd, same functionality as j in autojump
alias zz='fasd_cd -d -i' # cd with interactive selection
# from: https://github.com/clvv/fasd/issues/10
# since I can only load auto configuration and have default fasd_cd AND useless aliases
# or manually load the modules and NOT have fasd_cd
# it's easier to use this function
fasd_cd() {
fasd_ret="$(fasd -d "$@")"
if [ -d "$fasd_ret" ]; then
cd "$fasd_ret" || exit
else
print "$fasd_ret"
fi
unset fasd_ret
}

View File

@ -0,0 +1,214 @@
#!/bin/bash
## Integration at the Bottom
# Copyright (C) 2011 by Wayne Walker <wwalker@solid-constructs.com>
#
# Released under one of the versions of the MIT License.
#
# Copyright (C) 2011 by Wayne Walker <wwalker@solid-constructs.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
_LIVE_AGENT_LIST=""
declare -a _LIVE_AGENT_SOCK_LIST
_LIVE_AGENT_SOCK_LIST=()
_debug_print() {
if [[ $_DEBUG -gt 0 ]]; then
printf "%s\n" "$1"
fi
}
find_all_ssh_agent_sockets() {
_SSH_AGENT_SOCKETS=$(find /tmp/ -type s -name agent.\* 2>/dev/null | grep '/tmp/ssh-.*/agent.*')
_debug_print "$_SSH_AGENT_SOCKETS"
}
find_all_gpg_agent_sockets() {
_GPG_AGENT_SOCKETS=$(find /tmp/ -type s -name S.gpg-agent.ssh 2>/dev/null | grep '/tmp/gpg-.*/S.gpg-agent.ssh')
_debug_print "$_GPG_AGENT_SOCKETS"
}
find_all_gnome_keyring_agent_sockets() {
_GNOME_KEYRING_AGENT_SOCKETS=$(find /tmp/ -type s -name "ssh" 2>/dev/null | grep '/tmp/keyring-.*/ssh$')
_debug_print "$_GNOME_KEYRING_AGENT_SOCKETS"
}
find_all_osx_keychain_agent_sockets() {
[[ -n "$TMPDIR" ]] || TMPDIR=/tmp
_OSX_KEYCHAIN_AGENT_SOCKETS=$(find $TMPDIR/ -type s -regex '.*/ssh-.*/agent..*$' 2>/dev/null)
_debug_print "$_OSX_KEYCHAIN_AGENT_SOCKETS"
}
test_agent_socket() {
local SOCKET=$1
SSH_AUTH_SOCK=$SOCKET ssh-add -l 2>/dev/null >/dev/null
result=$?
_debug_print $result
if [[ $result -eq 0 ]]; then
# contactible and has keys loaded
_KEY_COUNT=$(SSH_AUTH_SOCK=$SOCKET ssh-add -l | wc -l | tr -d ' ')
fi
if [[ $result -eq 1 ]]; then
# contactible butno keys loaded
_KEY_COUNT=0
fi
if [ $result -eq 0 ] || [ $result -eq 1 ]; then
if [[ -n "$_LIVE_AGENT_LIST" ]]; then
_LIVE_AGENT_LIST="${_LIVE_AGENT_LIST} ${SOCKET}:$_KEY_COUNT"
else
_LIVE_AGENT_LIST="${SOCKET}:$_KEY_COUNT"
fi
return 0
fi
return 1
}
find_live_gnome_keyring_agents() {
for i in $_GNOME_KEYRING_AGENT_SOCKETS; do
test_agent_socket "$i"
done
}
find_live_osx_keychain_agents() {
for i in $_OSX_KEYCHAIN_AGENT_SOCKETS; do
test_agent_socket "$i"
done
}
find_live_gpg_agents() {
for i in $_GPG_AGENT_SOCKETS; do
test_agent_socket "$i"
done
}
find_live_ssh_agents() {
for i in $_SSH_AGENT_SOCKETS; do
test_agent_socket "$i"
done
}
function fingerprints() {
local file="$1"
while read -r l; do
[[ -n $l && ${l###} == "$l" ]] && ssh-keygen -l -f /dev/stdin <<<"$l"
done <"$file"
}
find_all_agent_sockets() {
_SHOW_IDENTITY=0
if [ "$1" = "-i" ]; then
_SHOW_IDENTITY=1
fi
_LIVE_AGENT_LIST=
find_all_ssh_agent_sockets
find_all_gpg_agent_sockets
find_all_gnome_keyring_agent_sockets
find_all_osx_keychain_agent_sockets
find_live_ssh_agents
find_live_gpg_agents
find_live_gnome_keyring_agents
find_live_osx_keychain_agents
_debug_print "$_LIVE_AGENT_LIST"
_LIVE_AGENT_LIST=$(echo $_LIVE_AGENT_LIST | tr ' ' '\n' | sort -n -t: -k 2 -k 1 | uniq)
_LIVE_AGENT_SOCK_LIST=()
_debug_print "SORTED: $_LIVE_AGENT_LIST"
if [[ $_SHOW_IDENTITY -gt 0 ]]; then
i=0
for a in $_LIVE_AGENT_LIST; do
sock=${a/:*/}
_LIVE_AGENT_SOCK_LIST[$i]=$sock
# technically we could have multiple keys forwarded
# But I haven't seen anyone do it
akeys=$(SSH_AUTH_SOCK=$sock ssh-add -l)
fingerprint=$(echo "${akeys}" | awk '{print $2}')
if [ -e ~/.ssh/authorized_keys ]; then
authorized_entry=$(fingerprints ~/.ssh/authorized_keys | grep "$fingerprint")
fi
comment=$(echo "${authorized_entry}" | awk '{print $3,$4,$5,$6,$7}')
printf "export SSH_AUTH_SOCK=%s \t#%i) \t%s\n" "$sock" $((i + 1)) "$comment"
i=$((i + 1))
done
else
printf "%s\n" "$_LIVE_AGENT_LIST" | sed -e 's/ /\n/g' | sort -n -t: -k 2 -k 1
fi
}
set_ssh_agent_socket() {
if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then
find_all_agent_sockets -i
if [ -z "$_LIVE_AGENT_LIST" ]; then
echo "No agents found"
return 1
fi
echo -n "Choose (1-${#_LIVE_AGENT_SOCK_LIST[@]})? "
read -r choice
if [ -n "$choice" ]; then
n=$((choice - 1))
if [ -z "${_LIVE_AGENT_SOCK_LIST[$n]}" ]; then
echo "Invalid choice"
return 1
fi
echo "Setting export SSH_AUTH_SOCK=${_LIVE_AGENT_SOCK_LIST[$n]}"
export SSH_AUTH_SOCK=${_LIVE_AGENT_SOCK_LIST[$n]}
fi
else
# Choose the first available
SOCK=$(find_all_agent_sockets | tail -n 1 | awk -F: '{print $1}')
if [ -z "$SOCK" ]; then
return 1
fi
export SSH_AUTH_SOCK=$SOCK
fi
# set agent pid
if [ -n "$SSH_AUTH_SOCK" ]; then
export SSH_AGENT_PID=$(($(echo "$SSH_AUTH_SOCK" | cut -d. -f2) + 1))
fi
return 0
}
ssh-find-agent() {
if [ "$1" = "-c" ] || [ "$1" = "--choose" ]; then
set_ssh_agent_socket -c
return $?
elif [ "$1" = "-a" ] || [ "$1" = "--auto" ]; then
set_ssh_agent_socket
return $?
else
find_all_agent_sockets -i
return 0
fi
}
# Automatically add ssh-agent to any new ssh connection
ssh-find-agent -a
if [ -z "$SSH_AUTH_SOCK" ]; then
eval "$(ssh-agent)" >/dev/null
ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh'
fi

View File

@ -36,6 +36,9 @@ export FILEREADER="zathura"
export FILEMANAGER="vifm"
## gopath
export GOPATH="$HOME/projects/gopath/"
export PATH="$PATH:$GOPATH/bin"
## LANG LOCALE UTF-8
export LC_ALL="en_US.utf-8"
export LANG="en_US.utf-8"

1198
zsh/.config/zsh/.p10k.zsh Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,31 @@
#!/usr/bin/env zsh
#
#
# Set completion style
# The following lines were added by compinstall
zstyle ':completion:*' completer _complete _ignored _approximate
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' matcher-list '' '+m:{[:lower:]}={[:upper:]} r:|[._-]=** r:|=**'
zstyle ':completion:*' menu select=1
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle :compinstall filename '/home/marty/.config/zsh/.zshrc'
# End of lines added by compinstall
autoload -Uz compinit zmv
compinit
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.config/zsh/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block, everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# load all plugins
[ -f "$XDG_CONFIG_HOME/zsh/plugins.zsh" ] && source "$XDG_CONFIG_HOME/zsh/plugins.zsh"
# shellcheck source=alias
[ -f "$XDG_CONFIG_HOME/sh/alias" ] && . "$XDG_CONFIG_HOME/sh/alias"
[ -f "$XDG_CONFIG_HOME/sh/alias" ] && source "$XDG_CONFIG_HOME/sh/alias"
# load additional aliases
if [ -d "$XDG_CONFIG_HOME/sh/alias.d" ]; then
for _alias in "$XDG_CONFIG_HOME/sh/alias.d"/*.sh; do
@ -12,11 +34,79 @@ if [ -d "$XDG_CONFIG_HOME/sh/alias.d" ]; then
unset _alias
fi
# history
#
# Correct spelling for commands
setopt correct
# turn off the infernal correctall for filenames
unsetopt correctall
# Enable command auto-correction.
ENABLE_CORRECTION="true"
# Speed up autocomplete, force prefix mapping
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
# shellcheck disable=SC2016
zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)*==34=34}:${(s.:.)LS_COLORS}")'
### history
## Set ZSH History defaults
setopt append_history
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_all_dups
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_reduce_blanks
setopt hist_save_no_dups
setopt hist_verify
# Share your history across all your terminal windows
setopt share_history
setopt pushd_ignore_dups
#setopt pushd_silent
export HISTSIZE=100000
export SAVEHIST=100000
export HISTFILE="$XDG_DATA_HOME/zsh_history"
export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help"
## Set ZSH History aliases
# Show the top 5 commands used in recent history
history_top() {
history | awk "{a[\$2]++} END{for(i in a){printf \"%5d\t%s\n\",a[i],i}}" | sort -rn | head
}
# Display timestamped recent command history
alias history="fc -l -d -D"
### Glob Alias expansion
# Expand aliases inline - see http://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html
globalias() {
if [[ $LBUFFER =~ [A-Z0-9]+$ ]]; then
zle _expand_alias
zle expand-word
fi
zle self-insert
}
zle -N globalias
bindkey " " globalias
bindkey "^ " magic-space # control-space to bypass completion
bindkey -M isearch " " magic-space # normal space during searches
# To customize prompt, run `p10k configure` or edit ~/.config/zsh/.p10k.zsh.
[[ ! -f "$XDG_CONFIG_HOME"/zsh/.p10k.zsh ]] || source "$XDG_CONFIG_HOME"/zsh/.p10k.zsh
# In case a plugin adds a redundant path entry, remove duplicate entries
# from PATH
# from: https://unix.stackexchange.com/questions/40749/remove-duplicate-path-entries-with-awk-command
get_var() {
eval 'printf "%s\n" "${'"$1"'}"'
}
set_var() {
eval "$1=\"\$2\""
}
dedup_pathvar() {
pathvar_name="$1"
pathvar_value="$(get_var "$pathvar_name")"
deduped_path="$(perl -e 'print join(":",grep { not $seen{$_}++ } split(/:/, $ARGV[0]))' "$pathvar_value")"
set_var "$pathvar_name" "$deduped_path"
}
dedup_pathvar PATH
dedup_pathvar MANPATH

View File

@ -0,0 +1,73 @@
#!/bin/zsh
# Clone zgen if you haven't already
check_zgen_installation() {
if [[ -z "$ZGEN_PARENT_DIR" ]]; then
ZGEN_PARENT_DIR=${XDG_DATA_HOME:="$HOME/.local/share"}
ZGEN_DIR="$ZGEN_PARENT_DIR/zgen"
fi
if [[ ! -f $ZGEN_DIR/zgen.zsh ]]; then
if [[ ! -d "$ZGEN_PARENT_DIR" ]]; then
mkdir -p "$ZGEN_PARENT_DIR"
fi
cd "$ZGEN_PARENT_DIR" || return
git clone https://github.com/tarjoilija/zgen.git "$ZGEN_DIR"
fi
# shellcheck source=/home/marty/.config/zgen/zgen.zsh
# shellcheck disable=SC1091
source "$ZGEN_DIR"/zgen.zsh
unset ZGEN_PARENT_DIR
}
load_plugins() {
ZGEN_LOADED=()
ZGEN_COMPLETIONS=()
zgen oh-my-zsh
# If you want to customize your plugin list, create a file named
# .zgen-local-plugins in your home directory. That file will be sourced
# during startup *instead* of running this load-starter-plugin-list function,
# so make sure to include everything from this function that you want to keep.
# If zsh-syntax-highlighting is bundled after zsh-history-substring-search,
# they break, so get the order right.
zgen load zdharma/fast-syntax-highlighting
# zgen load zsh-users/zsh-history-substring-search
# # Set keystrokes for substring searching
# zmodload zsh/terminfo
# bindkey "${terminfo[kcuu1]:?}" history-substring-search-up
# bindkey "${terminfo[kcud1]:?}" history-substring-search-down
# Automatically run zgen update and zgen selfupdate every 7 days.
zgen load unixorn/autoupdate-zgen
# Warn you when you run a command that you've set an alias for without
# using the alias.
zgen load djui/alias-tips
# Add Fish-like autosuggestions to your ZSH.
zgen load zsh-users/zsh-autosuggestions
zgen load romkatv/powerlevel10k powerlevel10k
# radically enhanced cd command, all sorts of options
# zgen load b4b4r07/enhancd
# set up nvm, the npm version manager
zgen load lukechilds/zsh-nvm
# Add git helper scripts.
zgen oh-my-zsh plugins/git
zgen oh-my-zsh plugins/colored-man-pages
# Load me last
GENCOMPL_FPATH=${XDG_CONFIG_HOME:-"$HOME/.config/zsh"}/complete
zgen save
}
check_zgen_installation
if ! zgen saved; then
load_plugins
fi