Notes to Self

Alex Sokolsky's Notes on Computers and Programming

Linux Dot Files

Approaches to managing dot files:

.nanorc

# Version: nano 6.2
# from https://github.com/davidhcefx/Modern-Nano-Keybindings
# Syntax highlights (path might be different)
include "/usr/share/nano/*.nanorc"
include "/usr/share/nano/extra/*.nanorc"

# Options
set tabsize 4
set tabstospaces
set linenumbers
set numbercolor yellow,normal
set indicator   # side-bar for indicating cur position
set mouse       # enable mouse support
set smarthome   # `Home` jumps to line start first
set zap         # delete selected text as a whole
set afterends   # `Ctrl+Right` move to word ends instead of word starts
set wordchars "_"   # recognize '_' as part of a word
set historylog      # remember search history
set multibuffer     # read files into multibuffer instead of insert

unbind ^Y  main  # remove unused bindings
unbind ^A  main
unbind M-Q all

#####  Modern Nano Keybindings  #####
## M-U   undo
## M-R   redo
## ^-C   copy
## ^-X   cut
## ^-V   paste
## ^-K   delete line
## ^-bsp delete until word start (or M-bsp)
## ^-del delete until next word
## ^-L   refresh and center cursor
## ^-S   save file
## M-/   comment/uncomment
## M-V   insert keystroke verbatim
## M-:   record macro
## M-;   play macro
## ^-Space  autocomplete word

## M-C   cursor position
## ^-W   search forward (= M-W + prompt)
## ^-E   seach backwards (= M-E + prompt)
## ^-R   replace
## ^-up  goto previous block
## ^-dn  goto next block
## M-(   goto block begin
## M-)   goto block end
## ^_    goto line/coloumn number
## ^-G   head of file (vim-like)
## M-G   end of file
## M-up  screen up one line
## M-dn  screen down one line
## M-]   goto matching bracket
## M-ins   insert anchor
## M-pgup  goto previous anchor
## ^-T   terminal (eg. |xxd)

bind M-R  redo          main
bind ^C   copy          main
bind ^X   cut           main
bind ^V   paste         main
bind ^K   zap           main
bind ^H   chopwordleft  all
bind ^Q   exit          all
bind ^Z   suspend       main
bind M-/  comment       main
bind ^Space complete    main

bind M-C  curpos        main
bind ^E   wherewas      all
bind M-E  findprevious  all
bind ^R   replace       main
bind ^B   pageup        all  # vim-like support
bind ^F   pagedown      all
bind ^G   firstline     all
bind M-G  lastline      all
bind M-1  help          all  # fix ^G been used
bind Sh-M-C  constantshow  main  # fix M-C been used

zsh startup

.zshenv → [.zprofile if login] → [.zshrc if interactive] → [.zlogin if login] → [.zlogout sometimes]

.zshenv is always sourced. It contains exported variables that should be available to other programs, e.g. $PATH, $EDITOR, $PAGER.

.zprofile is the same as .zlogin except that it’s sourced before .zshrc while .zlogin is sourced after .zshrc. According to the zsh documentation:

.zprofile is meant as an alternative to .zlogin for ksh fans; the two are not intended to be used together, although this could certainly be done if desired.

.zshrc is for interactive shell configuration:

.zlogin is sourced on the start of a login shell but after .zshrc if the shell is also interactive. This file is often used to start X. Some systems start X on boot, so this file is not always very useful.

.zshenv

# .zshenv is sourced on all invocations of the shell, unless the -f option is
# set. It should contain commands to set the command search path, plus other
# important environment variables.
# .zshenv should NOT contain commands that produce output or assume the shell
# is attached to a tty.

export AWS_DEFAULT_REGION=us-east-1
export AWS_PAGER=''

export GOROOT=$HOME/go
export PDSH_RCMD_TYPE=ssh
export EDITOR=emacs
if [ "$INSIDE_EMACS" ]; then
    export PAGER="/usr/bin/more"
else
    export PAGER="/usr/bin/less"
    export LESS="-isR"
    #alias lv="less"
fi

case "$AWS_VAULT" in
    "dev-from-security"|"dev-from-sso" )
        export KUBECONFIG="$HOME/.kube/dev-config" ;;
    *)
        export KUBECONFIG="$HOME/.kube/config" ;;
esac

.zprofile

# .zprofile is similar to .zlogin, except that it is sourced before .zshrc.
# .zprofile is meant as an alternative to .zlogin for ksh fans;
# the two are not intended to be used together,
# although this could certainly be done.
if [ -f ~/.zsh_aliases ]; then
    . ~/.zsh_aliases
fi

eval "$(ssh-agent -s)"
# add more IDs as needed
ssh-add -q ~/.ssh/id_rsa ~/.ssh/latitude_id_rsa

.zshrc

# .zshrc is sourced in interactive shells.
# Should contain commands to set up aliases, functions, options, key bindings,
# etc.

# Set up the prompt
autoload -Uz promptinit
promptinit
prompt suse
# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }

# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats '[%b]'
#zstyle ':vcs_info:git*' actionformats "%r/%S %b %m%u%c "
#zstyle ':vcs_info:git*' actionformats "%s  %r/%S %b %m%u%c "

setopt histignorealldups sharehistory

# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e

# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history

# Use modern completion system
autoload -Uz compinit
compinit

zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true

zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'

# The following lines were added by compinstall
#zstyle :compinstall filename '/Users/asokolsky/.zshrc'
#autoload bashcompinit && bashcompinit
#autoload -Uz compinit && compinit
# End of lines added by compinstall

# install CLI completions
source <(kubectl completion zsh)
complete -C '/usr/local/bin/aws_completer' aws

#source $ZSH/oh-my-zsh.sh
#
# ensure the history is NOT shared between terminals
# https://linux.die.net/man/1/zshoptions
#
unsetopt inc_append_history
unsetopt share_history

More