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)"
|
2022-04-03 04:42:47 +02:00
|
|
|
export ALTERNATE_EDITOR="$(command -v nano)"
|
2022-03-18 14:34:27 +01:00
|
|
|
elif command -v vim > /dev/null; then
|
|
|
|
VISUAL="$(command -v vim)"
|
|
|
|
fi
|
|
|
|
export VISUAL
|
|
|
|
export EDITOR="${VISUAL}"
|
|
|
|
|
|
|
|
############################# Plugins ##########################################
|
|
|
|
|
2022-04-05 15:28:54 +02:00
|
|
|
# Generate plugin lists and update or install them
|
|
|
|
source "${ZDOTDIR}"/plugins.zsh
|
2022-03-18 14:34:27 +01:00
|
|
|
|
|
|
|
############################# Variables ########################################
|
|
|
|
|
2022-03-29 16:01:56 +02:00
|
|
|
# Stop at chars not in there with backward-word and so on
|
2022-04-03 06:19:07 +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.
|
2022-04-02 17:40:33 +02:00
|
|
|
if [[ "${LC_TIME}" != "en_DK.utf8" ]] && command -v locale > /dev/null; then
|
|
|
|
[[ "$(locale --all-locales)" =~ "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-02 15:49:03 +02:00
|
|
|
# Config files (brown)
|
|
|
|
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;130" cfg json ini conf yml yaml xml toml)"
|
2022-04-01 03:23:56 +02:00
|
|
|
# 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-04-08 00:35:06 +02:00
|
|
|
[[ -f "${ZDOTDIR}"/secrets.zsh ]] && source "${ZDOTDIR}"/secrets.zsh
|
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
|
|
|
|
|
|
|
|
}
|