From d569f3f7ac829693addfdc8ed656e70d80d7d467 Mon Sep 17 00:00:00 2001 From: sev Date: Tue, 23 Feb 2021 01:54:28 -0600 Subject: [PATCH] update zsh, X, gpg config; add ssh config, gpg bin significant changes: - gpg socket and ssh agents are now automatically forwarded - big zsh refactor with better gpg and ssh agent support, and better keybinds Xresources: - fix Xft gitconfig: - set default branch to master xinitrc: - remove outdated code to source site local/system scripts, that should not be our problem - load xrdb/xmodmap sooner - fix gnu find opt ordering - move ssh-agent to zsh startup - suppress test urxvtc output zsh: - move PATH, FPATH, LANG, XDG, ~/tmp to zshenv - shim /etc/zprofile changing path in .zprofile - move .zshrc contents to .zprofile - replace magic functions with add-zsh-hook and add-zle-hook-widget - automate bindkey with zkbd and terminfo bin: - add gpg-learn-keys for scd - fix pinentry gpg: - disable throw-keyids, this breaks other stuff install.sh: - do not run .zprofile - add .ssh folder support ssh: - add config --- base/.Xresources | 6 +- base/.gitconfig | 2 + base/.xinitrc | 51 +-- base/.zprofile | 374 +++++++++++++++--- .../functions/Prompts/prompt_arrows_setup | 8 +- base/.zshenv | 53 +++ base/.zshrc | 210 ---------- bin/gpg-learn-keys | 5 + bin/pinentry | 2 +- gpg/gpg.conf | 2 +- install.sh | 9 +- ssh/config | 4 + 12 files changed, 417 insertions(+), 309 deletions(-) create mode 100755 bin/gpg-learn-keys create mode 100644 ssh/config diff --git a/base/.Xresources b/base/.Xresources index 25934a0..e5ca679 100644 --- a/base/.Xresources +++ b/base/.Xresources @@ -2,11 +2,11 @@ *font: -windows-dina-medium-r-*-*-10-80-*-*-*-*-* *faceName: Dina *faceSize: 8 -Xft.antialias: true +Xft.antialias: 1 +Xft.rgba: rgb Xft.dpi: 96 -Xft.hinting: true +Xft.hinting: 1 Xft.hintstyle: hintslight -Xft.rgba: rgb ! theming Xcursor.theme: Paper-Mono-Dark diff --git a/base/.gitconfig b/base/.gitconfig index 5ed2164..8d0cd8f 100644 --- a/base/.gitconfig +++ b/base/.gitconfig @@ -8,3 +8,5 @@ pr = "!f() { git fetch -fu ${2:-origin} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f" [pull] ff = only +[init] + defaultBranch = master diff --git a/base/.xinitrc b/base/.xinitrc index 8862d13..30db18b 100644 --- a/base/.xinitrc +++ b/base/.xinitrc @@ -1,39 +1,23 @@ #!/bin/zsh # using zsh to load .zshenv (eg. for PATH) but file is sh-compatible -sysmodmap=/usr/local/etc/X11/xinit/.Xmodmap -sysresources=/usr/local/etc/X11/xinit/.Xresources -usermodmap=~/.Xmodmap -userresources=~/.Xresources - -if [ -f $sysresources ]; then - xrdb -merge $sysresources -fi -if [ -f $sysmodmap ]; then - xmodmap $sysmodmap -fi -if [ -f "$userresources" ]; then - xrdb -merge "$userresources" -fi -if [ -f "$usermodmap" ]; then - xmodmap "$usermodmap" -fi - -# redshift, root image -redon & -wall & - # Xorg settings +# TODO: create shim for cpp +xrdb -merge ~/.Xresources +xmodmap ~/.Xmodmap xset r rate 290 26 & xset m 1/1 0 & xset s off xset dpms 0 0 600 - -find -L "${XDG_DATA_HOME:-~/share}/fonts" -type d -mindepth 1 -maxdepth 2 | while read -r x; do +find -L "${XDG_DATA_HOME:-~/share}/fonts" -mindepth 1 -maxdepth 2 -type d | while read -r x; do [ -f "$x/fonts.dir" ] && xset +fp $x done xset fp rehash +# redshift, root image +redon & +wall & + # root terminal urxvt -name TermBg1 -override-redirect -geometry x5+0--1 \ -e tail -F /var/log/messages & @@ -48,13 +32,12 @@ dunst & mpc-notify -d & xautolock -time 10 -locker "$HOME/bin/lck" & xbanish & -eval `ssh-agent` if [ -z "$TERMINAL" -a \( -x $(which -a urxvtd | head -1) \) ]; then for i in 1 2; do # try to start client twice, once before checking for daemon # and another after trying to start it - urxvtc -e exit 2>/dev/null + urxvtc -e exit >/dev/null 2>&1 if [ $? -eq 2 ]; then # daemon not started, attempt to start once if [ $i -eq 1 ]; then @@ -72,21 +55,15 @@ if [ -z "$TERMINAL" -a \( -x $(which -a urxvtd | head -1) \) ]; then unset i fi -# try to wait for session to start +# taskbar +# sleep to wait for session to start fully (sleep 0.1 && tint2) & + # x220t # TODO: check hostname to load auxillary things # TODO: reformat for linux #(sleep 0.1 "$HOME/bin/acpi_ac" "0x0`sysctl -n hw.acpi.acline`") & -# load any global scripts -if [ -d /usr/local/etc/X11/xinit/xinitrc.d ]; then - for f in /usr/local/etc/X11/xinit/xinitrc.d/?*.sh; do - [ -x "$f" ] && . "$f" - done - unset f -fi - # start session if [ -z "$1" ]; then session=i3 @@ -95,7 +72,3 @@ else shift fi exec $session "$@" - -# cleanup -#TODO: trap this -ssh-agent -k diff --git a/base/.zprofile b/base/.zprofile index a0e4d36..acdd191 100644 --- a/base/.zprofile +++ b/base/.zprofile @@ -1,67 +1,347 @@ -### general exports +### imports +source ~/bin/.check-busybox + +### exports +## reset PATH to prevent /etc/zprofile from changing it +# some distros put non-interactive PATH in env and interactive PATH in profile; +# we want to make sure to always use ours regardless +if [[ -v _sev_backup_path ]] { + path=("${_backup_path[@]}" "${path[@]}") + export PATH + unset _sev_backup_path +} +## common export EDITOR=vim export PAGER=less -## lang -export CHARSET=UTF-8 -export LANG="en_US.UTF-8" -export LC_CTYPE="$LANG" +## grep +# XXX: deprecated in GNU +export GREP_OPTIONS=--color=auto ## histfile export HISTFILE=~/.histfile export HISTSIZE=1000 export SAVEHIST=1000 -## path -# /usr/{pkg,local,games} are unix/bsdisms -typeset -U PATH path -path=({~/,/,/usr/}sbin {~/,/,/usr/}bin /usr/pkg/{s,}bin /usr/X11R{7,6}/bin - /usr/local/{s,}bin /usr/games "${path[@]}") -export PATH -typeset -U FPATH fpath -fpath=(~/.zsh/functions/Prompts "${fpath[@]}") -export FPATH - -### applications ## python export PYTHONSTARTUP=~/.pythonrc ## perl -(( ${+commands[perl]} )) && eval $(perl -I $XDG_DATA_HOME/perl5/lib/perl5 -Mlocal::lib=$XDG_DATA_HOME/perl5 2>/dev/null) -## gpg -if (( ${+commands[gpg]} )) { - # SSH_AUTH_SOCK should be set in a remote SSH session for passthrough - # if it isn't, we are likely the first login shell on the local machine - # we also want to update USE_TTY if we are the login shell in graphics mode - if [[ ! -v SSH_AUTH_SOCK || -v DISPLAY ]] { - export GPG_TTY=$(tty) - export PINENTRY_USER_DATA=USE_TTY=$((! ${+DISPLAY})) - gpg-connect-agent UPDATESTARTUPTTY /bye >/dev/null +[[ -v commands[perl] ]] && eval $(perl -I $XDG_DATA_HOME/perl5/lib/perl5 -Mlocal::lib=$XDG_DATA_HOME/perl5 2>/dev/null) + +### ssh agents +# NOTE: preferred order of agents to check: okcagent, gnupg, openssh +# first block takes care of okcagent and openssh, second handles gnupg +if [[ ! -v SSH_AUTH_SOCK && ( -v commands[okc-ssh-agent] || + ( -v commands[ssh-agent] && ! -v commands[gpg] ) ) ]] { + okc=${commands[okc-ssh-agent]:+okc-} + agentfile=~/tmp/${okc}ssh-agent-exports + typeset sock= + typeset -i pid= + if [[ -f "$agentfile" ]] { + IFS=$'\0' read -r sock pid <"$agentfile" + } + if [[ -S "$sock" && $pid -gt 0 ]] && kill -0 $pid; then + echo "Reusing ${okc+okc-ssh-}agent pid $pid" + export SSH_AUTH_SOCK="$sock" + export SSH_AGENT_PID=$pid + else + # TODO: ensure ssh-agent path looks legit + # to avoid unsafe eval? + eval `${okc}ssh-agent` + echo -n "$SSH_AUTH_SOCK"$'\0'$SSH_AGENT_PID >!$agentfile + fi + unset okc agentfile sock pid +} elif [[ -v commands[gpg] && ! -S $_GNUPG_SOCK_DEST && \ + ( ! -v SSH_AUTH_SOCK || -v DISPLAY ) ]] { + export GPG_TTY=$(tty) + export PINENTRY_USER_DATA=USE_TTY=$((!${+DISPLAY})) + gpg-connect-agent UPDATESTARTUPTTY /BYE >/dev/null 2>&1 + [[ ! -v SSH_AUTH_SOCK ]] && \ export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) +} + +### gpg socket +if [[ -v _GNUPG_SOCK_SRC && -v _GNUPG_SOCK_DEST && -S $_GNUPG_SOCK_DEST ]] { + unlink $_GNUPG_SOCK_SRC >/dev/null 2>&1 + mv $_GNUPG_SOCK_DEST $_GNUPG_SOCK_SRC >/dev/null +} + +### options +setopt NO_BEEP NO_CLOBBER +## cd +setopt AUTO_CD CDABLE_VARS +## completion +setopt GLOB_COMPLETE +## line +setopt EXTENDED_GLOB GLOB_DOTS MARK_DIRS NOMATCH NUMERIC_GLOB_SORT +## prompt +setopt PROMPT_SUBST +## jobs +setopt AUTO_CONTINUE +## history +setopt NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY + +### keys +# TODO: investigate "^[[200~" bracketed-paste +bindkey -v +KEYTIMEOUT=10 +## populate key array +if (( $#terminfo == 0 )) { + # terminfo is not set or empty + function find_keymap { + for f in ${ZDOTDIR:-$HOME}/.zkbd/${TERM}{-${DISPLAY:-${VENDOR}-${OSTYPE}},} + [[ -f $f ]] && keymap=$f && break + } + find_keymap + if [[ -z $keymap ]] { + if read -q "?Can't read terminfo. Add new zkbd keymap? [y/N]"; then + echo + autoload -Uz zkbd && zkbd + unfunction zkbd + find_keymap + fi + echo } + if [[ -n $keymap ]] { + source $keymap + } else { + echo "Failed to source file $keymap" >&2 + } + unfunction find_keymap; unset keymap +} else { + # activate application mode for zle so terminfo keys work + # don't do this for zkbd since application mode shouldn't have ben enabled + if [[ -v terminfo[smkx] && -v terminfo[rmkx] ]] { + autoload -Uz add-zle-hook-widget + function _enter-application-mode { echoti smkx } + add-zle-hook-widget line-init _enter-application-mode + function _exit-application-mode { echoti rmkx } + add-zle-hook-widget line-finish _exit-application-mode + trap _exit-application-mode EXIT + } + # match zkbd hash as best we can to terminfo + typeset -gA key + key[F1]=$terminfo[kf1] + key[F2]=$terminfo[kf2] + key[F3]=$terminfo[kf3] + key[F4]=$terminfo[kf4] + key[F5]=$terminfo[kf5] + key[F6]=$terminfo[kf6] + key[F7]=$terminfo[kf7] + key[F8]=$terminfo[kf8] + key[F9]=$terminfo[kf9] + key[F10]=$terminfo[kf10] + key[F11]=$terminfo[kf11] + key[F12]=$terminfo[kf12] + key[Backspace]=$terminfo[kbs] + key[Insert]=$terminfo[kich1] + key[Home]=$terminfo[khome] + key[PageUp]=$terminfo[kpp] + key[Delete]=$terminfo[kdch1] + key[End]=$terminfo[kend] + key[PageDown]=$terminfo[knp] + key[Up]=$terminfo[kcuu1] + key[Down]=$terminfo[kcud1] + key[Left]=$terminfo[kcub1] + key[Right]=$terminfo[kcuf1] + #key[Menu]=$terminfo[] #TODO: not in termcap? } -## xdg -export XDG_CONFIG_HOME=~/etc -export XDG_CONFIG_DIRS=~/.config:/usr/pkg/etc/xdg:/usr/local/etc/xdg:/etc/xdg -export XDG_DATA_HOME=~/share -export XDG_DATA_DIRS=~/.local/share:/usr/pkg/share:/usr/local/share:/usr/share -export XDG_CACHE_HOME=~/tmp -export XDG_RUNTIME_DIR=~/tmp -## grep -# XXX: deprecated in GNU -export GREP_OPTIONS=--color=auto -### tmp -t="${TMPDIR:-/tmp}/home-$LOGNAME" -h="$HOME/tmp" -if [[ ! -e "$t" ]] { - mkdir -m 700 "$t" > /dev/null 2>&1 - #TODO: check if dir exists after mkdir +## bind keys in both viins and vicmd modes +function multibind { + local k=$key[$1] + if [[ -n $k ]] { + bindkey -- $k $2 + if [[ -v 3 ]] { + # - will use same command as viins + bindkey -a -- $k ${3:/-/$2} + } + } +} +multibind Backspace backward-delete-char vi-backward-char +multibind Insert overwrite-mode vi-insert +multibind Home beginning-of-line - +multibind PageUp up-line-or-history - +multibind Delete delete-char vi-delete-char +multibind End end-of-line - +multibind PageDown down-line-or-history - +multibind Left backward-char vi-backward-char +multibind Right forward-char vi-forward-char +## history search +autoload -Uz up-line-or-beginning-search down-line-or-beginning-search +zle -N up-line-or-beginning-search +multibind Up up-line-or-beginning-search - +zle -N down-line-or-beginning-search +multibind Down down-line-or-beginning-search - +unfunction multibind + +### aliases +alias h="history -25" +alias j="jobs -l" +alias l="ls -AF" +alias p="${PAGER:-more}" # TODO: make sure more is there or use safe default +alias e="${EDITOR:-vi}" # TODO: make sure vi is there or use safe default +if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] { + alias ll="ls -lAFho" +} else { + alias ll="ls -lAFh" +} +alias se=sudoedit +## ps +local p= +if which pstree >/dev/null 2>&1 && ! check-busybox pstree; then + # use pstree, but NOT busybox pstree because it kinda sucks + p="pstree -wg3" +elif [[ "$OSTYPE" =~ '^freebsd' ]]; then + p="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \ + -o%cpu,%mem,tty,stat,start=START -oetime,command" +elif check-busybox ps; then + # busybox compatible + p="ps -eouser='USR ' -ogroup='GRP ' \ + -opid=' PID' -onice=' NI' -ovsz=' MEM' \ + -otty,stat,etime,comm" +else + # XXX: untested, posix + # TODO: support gnu ps + p="ps -eouser=USR -ogroup=GRP -opid,nice=NI \ + -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm" +fi +if [[ "$(basename "$PAGER")" = "less" ]] { + p="$p | less -SE" +} else { + p="$p | \"${PAGER:-more}\"" } -#allow opaque entries to override link creation -if [[ ! -e "$h" ]] { - ln -sf "$t" "$h" > /dev/null 2>&1 +alias pa="$p" +alias spa="sudo $p" +unset p +## py venv +alias va="source bin/activate" +alias vd="deactivate" +## be paranoid +alias cp='cp -ip' +alias mv='mv -i' +if [[ "$OSTYPE" =~ '^freebsd' ]] { + # don't confirm if only a few files are deleted + alias rm='rm -I' +} else { + # TODO: similar behavior for non-freebsd, or impliment in zsh + alias rm='rm -i' +} +## go up directories +function up { + cd $(printf '../%.0s' {1..${1:-1}}) } -unset t -unset h + +### hooks +autoload -Uz add-zsh-hook +_sev_exectime= +function sev_precmd { + # change terminal title + # TODO: update and send BEL when job status changes + print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\" + # bell if exec takes 5s + if (( SECONDS - _sev_exectime >= 5 )) print "\a" + # we could update vcs_info here, but let prompt take care of it + # if it doesn't use vcs, it can be ignored safely +} +add-zsh-hook precmd sev_precmd +function sev_preexec { + # change terminal title to show command + print -Pnf "\e]2;%s\e\\" "%#${SSH_CLIENT+$USER@$HOST:}$1" + # save last exec time for bell + # XXX: does not run for blank cmdline + _sev_exectime=$SECONDS +} +add-zsh-hook preexec sev_preexec +function sev_chpwd { + # echo dir on cwd change + ls -AF +} +add-zsh-hook chpwd sev_chpwd + +### system-specific configs and aliases +case "$OSTYPE"; in + freebsd*) + # colors + export CLICOLOR= + export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30' + + ## sound + function s { sysctl hw.snd.default_unit${1:+\=$1} } + alias vol mixer + + ## install port dependencies from pkg (like pkgsrc `bmake bin-install') + # XXX: should probably use package-depends where possible, breaks when + # port name is different to package name + # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc) + function portpkg { + case "$1" { + build|run) + sudo pkg install -AU $(make ${1}-depends-list | + sed 's_/usr/ports/_ _' | tr -d '\n') + ;; + *) echo "Usage: \`portpkg ' in a port directory" + return 1;; + } + };; + netbsd) + ## sound + function s { + if [[ -z "$1" ]] { + ll /dev/mixer /dev/sound /dev/audio + return + } + for x in mixer sound audio; do + ln -sf /dev/$x"$1" /dev/$x + done + } + function vol { + if [[ -z "$1" ]] { + for x in $(mixerctl -a | grep 'outputs\.master'); do + echo $x + done + return + } + mixerctl -w outputs.master"$2"="$1" + };; + *) + ## sound + # TODO: test alsa/oss/sndio/portaudio/pulse in order of importance + function s {} + function vol {} +esac + +### modules & styles +## vcs +zstyle ':vcs_info:*' enable git +#zstyle ':vcs_info:git*' check-for-changes true #too slow +zstyle ':vcs_info:git*:dotfiles' check-for-changes true +zstyle ':vcs_info:git*' check-for-staged-changes true +autoload -Uz vcs_info + +## compinit +zstyle ':completion:*' auto-description '[arg] %d' +zstyle ':completion:*' expand suffix +zstyle ':completion:*' format '# %d' +zstyle ':completion:*' group-name '' +zstyle ':completion:*' ignore-parents parent +zstyle ':completion:*' insert-unambiguous false +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*' list-prompt '%B%i%b' +zstyle ':completion:*' list-suffixes true +zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' +zstyle ':completion:*' menu select=1 +zstyle ':completion:*' original false +zstyle ':completion:*' select-prompt '%B%l%b' +zstyle ':completion:*' verbose true +autoload -Uz compinit && compinit + +## prompt +# do this last so prompt can potentially override other settings +autoload -Uz promptinit && promptinit +prompt arrows ### load site-specific if [[ -f ~/.zprofile.local ]] { source ~/.zprofile.local } +### unset imports +unfunction check-busybox + # vim: set et sts=4 sw=4 ts=8 tw=79 : diff --git a/base/.zsh/functions/Prompts/prompt_arrows_setup b/base/.zsh/functions/Prompts/prompt_arrows_setup index 77313c0..9b935f1 100644 --- a/base/.zsh/functions/Prompts/prompt_arrows_setup +++ b/base/.zsh/functions/Prompts/prompt_arrows_setup @@ -71,14 +71,16 @@ function prompt_arrows_setup() { zstyle ':vcs_info:git*' stagedstr "%F{$c}+" zstyle ':vcs_info:git*' unstagedstr "%F{$r}*" + # add-zsh-hook should have already been autoloaded by promptinit add-zsh-hook precmd prompt_arrows_precmd add-zsh-hook preexec prompt_arrows_preexec - zle -N zle-line-init - zle -A zle-line-init zle-keymap-select + autoload -Uz add-zle-hook-widget + add-zle-hook-widget line-init prompt_arrows_keymap_select + add-zle-hook-widget keymap-select prompt_arrows_keymap_select } # change color based on zle vi mode -function zle-line-init { +function prompt_arrows_keymap_select { prompt_arrows_vimode="${KEYMAP:/(main|viins)/}" zle reset-prompt } diff --git a/base/.zshenv b/base/.zshenv index 2ed1fc8..819eb70 100644 --- a/base/.zshenv +++ b/base/.zshenv @@ -1,3 +1,56 @@ +### exports for new non-interactive shell +if [[ $SHLVL == 1 ]] { + ## lang + export CHARSET=UTF-8 + export LANG="en_US.UTF-8" + export LC_CTYPE="$LANG" + + ## path + # /usr/{pkg,local,games} are unix/bsdisms + typeset -U PATH path + path=({~/,/,/usr/}sbin {~/,/,/usr/}bin /usr/pkg/{s,}bin /usr/X11R{7,6}/bin + /usr/local/{s,}bin /usr/games "${path[@]}") + export PATH + typeset -U _sev_backup_path + _sev_backup_path=("${path[@]}") + typeset -U FPATH fpath + fpath=(${ZDOTDIR:-$HOME/.zsh}/functions/{*,Completions/*}(N) "${fpath[@]}") + export FPATH + + ## xdg + export XDG_CONFIG_HOME=~/etc + export XDG_CONFIG_DIRS=~/.config:/usr/pkg/etc/xdg:/usr/local/etc/xdg:/etc/xdg + export XDG_DATA_HOME=~/share + export XDG_DATA_DIRS=~/.local/share:/usr/pkg/share:/usr/local/share:/usr/share + export XDG_CACHE_HOME=~/tmp + export XDG_RUNTIME_DIR=~/tmp + + # create tmp link + t="${TMPDIR:-/tmp}/home-$LOGNAME" + h="$HOME/tmp" + if [[ ! -e "$t" ]] { + mkdir -m 700 "$t" > /dev/null 2>&1 + # TODO: check if dir exists after mkdir + } + # allow opaque entries to override link creation + if [[ ! -e "$h" ]] { + ln -sf "$t" "$h" > /dev/null 2>&1 + } + unset t h +} + +### gpg ssh forwarding +# these env vars are used as arguments to RemoteForward in ~/.ssh/config +if [[ -v commands[gpgconf] && ! ( -v _GNUPG_SOCK_SRC && -v _GNUPG_SOCK_DEST ) ]] { + # if already connected over SSH, reuse forwarded socket for future + # connections; else use extra socket + sock=${SSH_CLIENT:+agent-socket} + export _GNUPG_SOCK_SRC=$(gpgconf --list-dirs ${sock:-agent-extra-socket}) + # XXX: chance of race condition + export _GNUPG_SOCK_DEST=/tmp/.gpg-agent-forward + unset sock +} + ### load site-specific if [[ -f ~/.zshenv.local ]] { source ~/.zshenv.local } diff --git a/base/.zshrc b/base/.zshrc index 644e178..af0becf 100644 --- a/base/.zshrc +++ b/base/.zshrc @@ -1,214 +1,4 @@ -### imports -source ~/bin/.check-busybox - -### options -setopt NO_BEEP NO_CLOBBER -## cd -setopt AUTO_CD CDABLE_VARS -## completion -setopt GLOB_COMPLETE -## line -setopt EXTENDED_GLOB GLOB_DOTS MARK_DIRS NOMATCH NUMERIC_GLOB_SORT -## prompt -setopt PROMPT_SUBST -## jobs -setopt AUTO_CONTINUE -## history -setopt NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY - -### keys -bindkey -v -KEYTIMEOUT=1 -## xorg -bindkey "^[[7~" beginning-of-line #Home -bindkey -a "^[[7~" beginning-of-line -bindkey "^[[8~" end-of-line #End -bindkey -a "^[[8~" end-of-line -bindkey "^[[3~" delete-char #Del -bindkey -a "^[[3~" delete-char -## history search -autoload -Uz up-line-or-beginning-search down-line-or-beginning-search && { - if [[ -n "$key[Up]" ]] { - zle -N up-line-or-beginning-search - bindkey -- "$key[Up]" up-line-or-beginning-search - } - if [[ -n "$key[Down]" ]] { - bindkey -- "$key[Down]" down-line-or-beginning-search - zle -N down-line-or-beginning-search - } -} - -### aliases -alias h="history -25" -alias j="jobs -l" -alias l="ls -AF" -alias e="${EDITOR:-vi}" # TODO: make sure vi is there or use safe default -if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] { - alias ll="ls -lAFho" -} else { - alias ll="ls -lAFh" -} -alias se=sudoedit -## ps -local p= -if which pstree >/dev/null 2>&1 && ! check-busybox pstree; then - # use pstree, but NOT busybox pstree because it kinda sucks - p="pstree -wg3" -elif [[ "$OSTYPE" =~ '^freebsd' ]]; then - p="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \ - -o%cpu,%mem,tty,stat,start=START -oetime,command" -elif check-busybox ps; then - # busybox compatible - p="ps -eouser='USR ' -ogroup='GRP ' \ - -opid=' PID' -onice=' NI' -ovsz=' MEM' \ - -otty,stat,etime,comm" -else - # XXX: untested, posix - # TODO: support gnu ps - p="ps -eouser=USR -ogroup=GRP -opid,nice=NI \ - -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm" -fi -if [[ "$(basename "$PAGER")" = "less" ]] { - p="$p | less -SE" -} else { - p="$p | \"${PAGER:-more}\"" -} -alias pa="$p" -alias spa="sudo $p" -unset p -## py venv -alias va="source bin/activate" -alias vd="deactivate" -## be paranoid -alias cp='cp -ip' -alias mv='mv -i' -if [[ "$OSTYPE" =~ '^freebsd' ]] { - # don't confirm if only a few files are deleted - alias rm='rm -I' -} else { - # TODO: similar behavior for non-freebsd, or impliment in zsh - alias rm='rm -i' -} -## go up directories -function up() { - cd $(printf '../%.0s' {1..${1:-1}}) -} - -### hooks -local _exectime= -function precmd { - # change terminal title - # TODO: update and send BEL when job status changes - print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\" - # bell if exec takes 5s - if ((SECONDS - _exectime >= 5)) print "\a" - # we could update vcs_info here, but let prompt take care of it - # if it doesn't use vcs, it can be ignored safely -} -function preexec { - # change terminal title to show command - print -Pnf "\e]2;%s\e\\" "%#${SSH_CLIENT+$USER@$HOST:}$1" - # save last exec time for bell - # XXX: does not run for blank cmdline - _exectime=$SECONDS -} -function chpwd { - # echo dir on cwd change - l -} - -### system-specific configs and aliases -case "$OSTYPE"; in - freebsd*) - ## vt binds - bindkey "^[[H" beginning-of-line #Home - bindkey -a "^[[H" beginning-of-line - bindkey "^[[F" end-of-line #End - bindkey -a "^[[F" end-of-line - - # colors - export CLICOLOR= - export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30' - - ## sound - function s { sysctl hw.snd.default_unit${1:+\=$1} } - alias vol mixer - - ## install port dependencies from pkg (like pkgsrc `bmake bin-install') - #XXX: should probably use package-depends where possible, breaks when - # port name is different to package name - # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc) - function portpkg { - case "$1" { - build|run) - sudo pkg install -AU $(make ${1}-depends-list | - sed 's_/usr/ports/_ _' | tr -d '\n') - ;; - *) echo "Usage: \`portpkg ' in a port directory" - return 1;; - } - };; - netbsd) - ## sound - function s { - if [[ -z "$1" ]] { - ll /dev/mixer /dev/sound /dev/audio - return - } - for x in mixer sound audio; do - ln -sf /dev/$x"$1" /dev/$x - done - } - function vol { - if [[ -z "$1" ]] { - for x in $(mixerctl -a | grep 'outputs\.master'); do - echo $x - done - return - } - mixerctl -w outputs.master"$2"="$1" - };; - *) - ## sound - # TODO: test alsa/oss/sndio/portaudio/pulse in order of importance - function s() {} - function vol() {} -esac - -### modules & styles -## vcs -zstyle ':vcs_info:*' enable git -#zstyle ':vcs_info:git*' check-for-changes true #too slow -zstyle ':vcs_info:git*:dotfiles' check-for-changes true -zstyle ':vcs_info:git*' check-for-staged-changes true -autoload -Uz vcs_info - -## compinit -zstyle ':completion:*' auto-description '[arg] %d' -zstyle ':completion:*' expand suffix -zstyle ':completion:*' format '# %d' -zstyle ':completion:*' group-name '' -zstyle ':completion:*' ignore-parents parent -zstyle ':completion:*' insert-unambiguous false -zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} -zstyle ':completion:*' list-prompt '%B%i%b' -zstyle ':completion:*' list-suffixes true -zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' -zstyle ':completion:*' menu select=1 -zstyle ':completion:*' original false -zstyle ':completion:*' select-prompt '%B%l%b' -zstyle ':completion:*' verbose true -autoload -Uz compinit && compinit - -## prompt -# do this last so prompt can potentially override other settings -autoload -Uz promptinit && promptinit -prompt arrows - ### load site-specific if [[ -f ~/.zshrc.local ]] { source ~/.zshrc.local } -### unset imports -unfunction check-busybox - # vim: set et sts=4 sw=4 ts=8 tw=79 : diff --git a/bin/gpg-learn-keys b/bin/gpg-learn-keys new file mode 100755 index 0000000..fc48cdb --- /dev/null +++ b/bin/gpg-learn-keys @@ -0,0 +1,5 @@ +#!/bin/sh +gpg-connect-agent </dev/null + p=`which "pinentry-$x"` 2>/dev/null if [ $? = 0 ]; then exec "$p" "$@" fi diff --git a/gpg/gpg.conf b/gpg/gpg.conf index 0b30d7a..dd983ed 100644 --- a/gpg/gpg.conf +++ b/gpg/gpg.conf @@ -29,7 +29,7 @@ with-key-origin # disable caching of passphrase for symmetrical ops no-symkey-cache # disable recipient key ID in messages -throw-keyids +#throw-keyids # keyservers keyserver hkps://keys.openpgp.org diff --git a/install.sh b/install.sh index 34722ed..886eb1e 100755 --- a/install.sh +++ b/install.sh @@ -21,7 +21,7 @@ fi # create preferred folder structure cd ~ -mkdir -p bin etc share share/fonts .urxvt/ext .icons .themes .gnupg >$devnull 2>&1 +mkdir -p bin etc share share/fonts .urxvt/ext .icons .themes .gnupg .ssh >$devnull 2>&1 mkdir -pm 700 var/tmp var/tmp/vim >$devnull 2>&1 cd - >$devnull @@ -78,7 +78,6 @@ if which gpg >/dev/null 2>&1; then gpg --import "$x" done fi - -# run .zprofile to set up tmp -# .zprofile also sources .zshenv for compatibility -zsh ~/.zprofile +find ssh -mindepth 1 -maxdepth 1 | while read -r x; do + l "$HOME/.ssh/`basename "$x"`" +done diff --git a/ssh/config b/ssh/config new file mode 100644 index 0000000..350df4b --- /dev/null +++ b/ssh/config @@ -0,0 +1,4 @@ +Host * + ForwardAgent yes + ForwardX11 yes + RemoteForward ${_GNUPG_SOCK_DEST} ${_GNUPG_SOCK_SRC} -- 2.47.0