2022-03-18 14:34:27 +01:00
|
|
|
function() # Keep local variables in here.
|
|
|
|
{
|
|
|
|
|
|
|
|
############################## Paths ###########################################
|
|
|
|
|
|
|
|
export PATH="${HOME}/bin:${HOME}/.local/bin:${PATH}"
|
|
|
|
export HISTFILE="${ZDOTDIR}/.zsh_history"
|
|
|
|
export ZSH_CACHE_DIR="${XDG_CACHE_HOME:-${HOME}/.cache}/zsh"
|
2022-03-18 15:21:50 +01:00
|
|
|
mkdir -p "${ZSH_CACHE_DIR}"
|
2022-03-18 14:34:27 +01:00
|
|
|
|
2022-03-28 06:14:46 +02:00
|
|
|
if [[ -d "${XDG_DATA_HOME:-${HOME}/.local/share}/man/" ]]; then
|
|
|
|
export MANPATH="${MANPATH}:${XDG_DATA_HOME:-${HOME}/.local/share}/man"
|
2022-03-18 14:34:27 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
############################ Editor ############################################
|
|
|
|
|
|
|
|
# Set preferred editor.
|
|
|
|
# Add Defaults env_keep += "SSH_CONNECTION" to /etc/sudoers.d/ssh_vars
|
|
|
|
if command -v emacsclient > /dev/null; then
|
|
|
|
export EMACS_SOCKET_NAME="${HOME}/.emacs.d/server/server"
|
|
|
|
if pgrep -f "emacs --daemon" > /dev/null; then
|
|
|
|
VISUAL="$(command -v emacsclient) -c"
|
|
|
|
else
|
|
|
|
VISUAL="$(command -v emacs)"
|
|
|
|
fi
|
2022-03-28 06:18:33 +02:00
|
|
|
if [[ ${EUID} -eq 0 ]]; then
|
2022-03-18 14:34:27 +01:00
|
|
|
# Edit files as root in the Emacs instance run by the current user.
|
|
|
|
VISUAL="$(command -v emacsremote) --sudo --local"
|
|
|
|
fi
|
|
|
|
elif command -v emacs > /dev/null; then
|
|
|
|
VISUAL="$(command -v emacs)"
|
|
|
|
elif command -v nano > /dev/null; then
|
|
|
|
VISUAL="$(command -v nano)"
|
|
|
|
elif command -v vim > /dev/null; then
|
|
|
|
VISUAL="$(command -v vim)"
|
|
|
|
fi
|
|
|
|
export VISUAL
|
|
|
|
export EDITOR="${VISUAL}"
|
|
|
|
export ALTERNATE_EDITOR="$(command -v nano)"
|
|
|
|
|
|
|
|
############################# Plugins ##########################################
|
|
|
|
|
2022-04-01 23:30:25 +02:00
|
|
|
zmodload zsh/stat
|
|
|
|
zmodload zsh/datetime
|
|
|
|
|
2022-03-18 14:34:27 +01:00
|
|
|
if command -v fzf > /dev/null; then
|
|
|
|
# Only load these plugins if fzf was found.
|
2022-03-28 06:51:55 +02:00
|
|
|
local _depends_on_fzf="Aloxaf/fzf-tab"
|
2022-03-18 14:34:27 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if command -v antibody > /dev/null; then
|
|
|
|
local plugin_cache_dir="$(antibody home)"
|
|
|
|
export ZSH_PLUGIN_SOURCE="${plugin_cache_dir}/antibody-plugins.zsh"
|
|
|
|
|
2022-03-28 06:51:55 +02:00
|
|
|
if [[ -f "${ZSH_PLUGIN_SOURCE}" ]] \
|
2022-04-01 23:30:25 +02:00
|
|
|
&& [[ $(zstat +size "${ZSH_PLUGIN_SOURCE}") -ne 0 ]]; then
|
|
|
|
local _plugins_modified=$(zstat +mtime "${ZSH_PLUGIN_SOURCE}")
|
|
|
|
local _now=$(strftime '%s')
|
2022-03-28 06:51:55 +02:00
|
|
|
# Update plugins every 10 days
|
2022-03-28 15:25:52 +02:00
|
|
|
if [[ $(( ${_now} - ${_plugins_modified} - 60 * 60 * 24 * 10)) -gt 0 ]]; then
|
2022-03-23 02:41:00 +01:00
|
|
|
print "\e[3;95mUpdating plugins…\e[0m"
|
2022-03-18 14:34:27 +01:00
|
|
|
antibody update --parallelism=$(nproc --ignore=1) \
|
2022-03-28 06:51:55 +02:00
|
|
|
&& touch "${ZSH_PLUGIN_SOURCE}"
|
2022-03-18 14:34:27 +01:00
|
|
|
fi
|
|
|
|
else
|
2022-03-23 02:42:10 +01:00
|
|
|
print "\e[3;95mInstalling plugins…\e[0m"
|
2022-03-28 06:51:55 +02:00
|
|
|
mkdir -p "${plugin_cache_dir}"
|
|
|
|
antibody bundle --parallelism=$(nproc --ignore=1) <<EOF > "${ZSH_PLUGIN_SOURCE}"
|
|
|
|
${_depends_on_fzf}
|
2022-03-18 14:34:27 +01:00
|
|
|
zsh-users/zsh-autosuggestions
|
|
|
|
mafredri/zsh-async
|
|
|
|
zsh-users/zsh-syntax-highlighting
|
2022-03-23 23:41:37 +01:00
|
|
|
# Must come after zsh-syntax-highlighting
|
|
|
|
zsh-users/zsh-history-substring-search
|
2022-03-18 14:34:27 +01:00
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
else
|
2022-03-28 06:51:55 +02:00
|
|
|
print -u 2 "\e[7;95mantibody not found.\e[0m"
|
2022-03-18 14:34:27 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
############################# Variables ########################################
|
|
|
|
|
2022-03-29 16:01:56 +02:00
|
|
|
# Stop at chars not in there with backward-word and so on
|
2022-03-29 17:24:59 +02:00
|
|
|
export WORDCHARS="${WORDCHARS//(\/|_|.)}"
|
2022-03-23 14:34:53 +01:00
|
|
|
|
2022-03-18 14:34:27 +01:00
|
|
|
# minicom color on.
|
|
|
|
export MINICOM="-c on -R utf-8"
|
|
|
|
|
|
|
|
export PASSWORD_STORE_GENERATED_LENGTH="43"
|
|
|
|
|
|
|
|
export LESS="--tabs=4 --RAW-CONTROL-CHARS --LONG-PROMPT"
|
|
|
|
|
|
|
|
if command -v highlight > /dev/null; then
|
2022-03-22 23:36:12 +01:00
|
|
|
# ~/.lessfilter handles the highlighting
|
|
|
|
LESSOPEN="| $(command -v lesspipe) %s"
|
2022-03-22 23:40:24 +01:00
|
|
|
export CATOPEN="highlight --validate-input --force --out-format=truecolor --style=base16/unikitty-reversible --stdout %s"
|
2022-03-22 01:00:14 +01:00
|
|
|
elif command -v pygmentize > /dev/null; then
|
|
|
|
LESSOPEN="| $(command -v pygmentize) -f terminal16m -g -O style=paraiso-dark %s"
|
|
|
|
elif command -v source-highlight > /dev/null; then
|
|
|
|
LESSOPEN="| $(command -v source-highlight) --failsafe --infer-lang --out-format=esc --style-file=esc.style --input=%s"
|
2022-03-18 14:34:27 +01:00
|
|
|
elif command -v lesspipe > /dev/null; then
|
2022-03-22 01:00:14 +01:00
|
|
|
LESSOPEN="| $(command -v lesspipe) %s"
|
|
|
|
elif command -v lesspipe.sh > /dev/null; then
|
|
|
|
LESSOPEN="| $(command -v lesspipe.sh) %s"
|
2022-03-18 14:34:27 +01:00
|
|
|
fi
|
|
|
|
export LESSOPEN
|
|
|
|
|
|
|
|
# Show AS for each hop.
|
|
|
|
export MTR_OPTIONS="-z"
|
|
|
|
|
|
|
|
# Set SDL soundfont.
|
|
|
|
if [[ -f "/usr/share/sounds/sf2/FluidR3_GM.sf2" ]]; then
|
|
|
|
export SDL_SOUNDFONTS="/usr/share/sounds/sf2/FluidR3_GM.sf2"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Make virsh use the local hypervisor by default.
|
|
|
|
if command -v virsh > /dev/null; then
|
|
|
|
export LIBVIRT_DEFAULT_URI="qemu:///system"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Use ISO 8601 date & time.
|
|
|
|
if command -v locale > /dev/null; then
|
2022-03-18 15:32:02 +01:00
|
|
|
locale -a | grep -q en_DK && export LC_TIME="en_DK.utf8"
|
2022-03-18 14:34:27 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
export CCACHE_DIR="/var/cache/ccache"
|
|
|
|
|
2022-03-18 15:32:02 +01:00
|
|
|
# Set terminal
|
|
|
|
if command -v alacritty > /dev/null; then
|
|
|
|
export TERMINAL="alacritty"
|
|
|
|
elif command -v xfce4-terminal > /dev/null; then
|
|
|
|
export TERMINAL="xfce4-terminal"
|
|
|
|
elif command -v urxvt > /dev/null; then
|
|
|
|
export TERMINAL="urxvt"
|
|
|
|
elif command -v xterm > /dev/null; then
|
|
|
|
export TERMINAL="xterm"
|
|
|
|
fi
|
|
|
|
|
2022-03-31 18:27:51 +02:00
|
|
|
# Add some nice colors to ls output
|
|
|
|
function _gen_lscolor()
|
|
|
|
{
|
|
|
|
local color="${1}"
|
|
|
|
shift
|
|
|
|
local -a extensions=("${@}")
|
|
|
|
|
|
|
|
for ext in ${extensions}; do
|
|
|
|
print -n ":*.${ext}=${color}"
|
|
|
|
done
|
|
|
|
}
|
2022-04-01 03:49:14 +02:00
|
|
|
unset LS_COLORS
|
2022-04-01 03:23:56 +02:00
|
|
|
# Program code (rose)
|
2022-04-02 00:09:04 +02:00
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;177" cpp cxx c++ c go rs ex)"
|
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;177" py rb el ebuild zsh sh bash pl php phtml qml js)"
|
2022-04-01 03:37:53 +02:00
|
|
|
# Stuff that gets included (violet + italic)
|
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "3;38;5;141" hpp hxx h++ h qss qrc)"
|
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "3;38;5;141" css sass scss tmpl csp inc)"
|
2022-04-01 03:23:56 +02:00
|
|
|
# Build systems and adjacent (green)
|
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;112" patch diff in cmake build mk ac m4 am)"
|
|
|
|
# Images, audio, video, playlists (yellow, orange, green)
|
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;184" webp png jpg jpeg gif svg svgz xcf bmp ico icns tiff tif xpm xbm tga ppm)"
|
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;172" flac opus ogg oga mp3 m4a wav mid midi wma ac3 au aac spx)"
|
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;172" mkv webm ogv ogm mp4 m4v avi mpeg mpg wmv flv mov 3gp asf)"
|
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;112" m3u m3u8 pls xspf)"
|
|
|
|
# Text (cyan)
|
2022-04-01 03:49:35 +02:00
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;117" txt md adoc org rst html xhtml shtml htm)"
|
2022-04-01 03:23:56 +02:00
|
|
|
# Config files (ochre)
|
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;100" cfg json ini conf yml yaml xml toml)"
|
|
|
|
# Compressed files and archives (red)
|
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;124" tar gz tgz zst bz2 xz lzma ar zip rar 7z Z arc lha cpio zoo)"
|
2022-03-31 23:53:52 +02:00
|
|
|
# Special cases
|
2022-04-01 03:23:56 +02:00
|
|
|
LS_COLORS="${LS_COLORS}:*Makefile=38;5;112:*CMakeLists.txt=38;5;112:*meson_options.txt=38;5;112"
|
|
|
|
LS_COLORS="${LS_COLORS}:*go.mod=38;5;112:*go.sum=38;5;112"
|
2022-03-31 18:27:51 +02:00
|
|
|
export LS_COLORS
|
|
|
|
unfunction _gen_lscolor
|
|
|
|
|
2022-03-18 14:34:27 +01:00
|
|
|
# Host specific settings.
|
2022-04-01 23:30:25 +02:00
|
|
|
case ${HOST} in
|
2022-03-18 14:34:27 +01:00
|
|
|
schnibble | gaffer | localhost)
|
|
|
|
export GIT_SSH_COMMAND="ssha" # Termux command for ssh with key-add.
|
|
|
|
export CPATH="/data/data/com.termux/files/usr/local/include"
|
|
|
|
export LIBRARY_PATH="/data/data/com.termux/files/usr/local/lib"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2022-03-19 03:54:51 +01:00
|
|
|
[[ -f "${ZDOTDIR}"/zsecrets ]] && source "${ZDOTDIR}"/zsecrets
|
2022-03-18 14:34:27 +01:00
|
|
|
|
|
|
|
############################# Daemons ##########################################
|
|
|
|
|
|
|
|
# Run SSH/GPG agents if they are installed and not already started. If they are
|
|
|
|
# started, attempt to inherit them.
|
|
|
|
if command -v keychain > /dev/null; then
|
2022-03-28 06:18:33 +02:00
|
|
|
if [[ $(pgrep --uid ${EUID} ssh-agent)
|
|
|
|
&& $(pgrep --uid ${EUID} gpg-agent) ]]; then
|
2022-03-18 14:34:27 +01:00
|
|
|
# Set environment variables from files.
|
|
|
|
if [[ -z "${SSH_AUTH_SOCK}" ]]; then
|
|
|
|
source "${HOME}/.keychain/$(hostname)-sh"
|
|
|
|
fi
|
|
|
|
if [[ -z "${GPG_AGENT_INFO}" ]]; then
|
|
|
|
source "${HOME}/.keychain/$(hostname)-sh-gpg"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Start SSH/GPG agents and write environment variables to files.
|
|
|
|
eval $(keychain --agents "ssh,gpg" \
|
|
|
|
--timeout $((60*16)) \
|
|
|
|
--inherit local \
|
|
|
|
--quiet --eval)
|
|
|
|
# <https://github.com/funtoo/keychain/issues/126>
|
|
|
|
eval $(keychain --agents "ssh,gpg" \
|
|
|
|
--timeout $((60*16)) \
|
|
|
|
--inherit local \
|
|
|
|
--quiet --eval)
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# keychain not installed, start SSH/GPG agents if they are not running.
|
|
|
|
if command -v ssh-agent > /dev/null \
|
2022-03-28 06:18:33 +02:00
|
|
|
&& [[ ! $(pgrep --uid ${EUID} ssh-agent) ]]; then
|
2022-03-18 14:34:27 +01:00
|
|
|
eval $(ssh-agent -t 16H 2> /dev/null)
|
|
|
|
fi
|
|
|
|
if command -v gpg-agent > /dev/null \
|
2022-03-28 06:18:33 +02:00
|
|
|
&& [[ ! $(pgrep --uid ${EUID} gpg-agent) ]]; then
|
2022-03-18 14:34:27 +01:00
|
|
|
eval $(gpg-agent --daemon --quiet --default-cache-ttl $((60*16)) \
|
|
|
|
--max-cache-ttl $((60*16)))
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
}
|