1
0
Fork 0
dotfiles/.config/zsh/.zprofile

188 lines
6.6 KiB
Bash

function() # Keep local variables in here.
{
############################## Paths ###########################################
path=(${HOME}/.local/bin ${path} ${HOME}/bin)
path=(${(u)path})
export HISTFILE="${ZDOTDIR}/.zsh_history"
export ZSH_CACHE_DIR="${XDG_CACHE_HOME:-${HOME}/.cache}/zsh"
mkdir -p "${ZSH_CACHE_DIR}"
if [[ -d "${XDG_DATA_HOME:-${HOME}/.local/share}/man/" ]]; then
manpath=(${manpath} ${XDG_DATA_HOME:-${HOME}/.local/share}/man)
manpath=(${(u)manpath})
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
if [[ ${EUID} -eq 0 ]]; then
# 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)"
export ALTERNATE_EDITOR="$(command -v nano)"
elif command -v vim > /dev/null; then
VISUAL="$(command -v vim)"
fi
export VISUAL
export EDITOR="${VISUAL}"
############################# Plugins ##########################################
# Generate plugin lists and update or install them
source "${ZDOTDIR}"/plugins.zsh
############################# Variables ########################################
# Stop at chars not in there with backward-word and so on
export WORDCHARS="${WORDCHARS//(\/|_|.|-)}"
# 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 lesspipe > /dev/null; then
LESSOPEN="| $(command -v lesspipe) %s"
elif command -v lesspipe.sh > /dev/null; then
LESSOPEN="| $(command -v lesspipe.sh) %s"
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 [[ "${LC_TIME}" != "en_DK.utf8" ]] && command -v locale > /dev/null; then
[[ "$(locale --all-locales)" =~ "en_DK" ]] && export LC_TIME="en_DK.utf8"
fi
export CCACHE_DIR="/var/cache/ccache"
# 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
# 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
}
unset LS_COLORS
# Program code (rose)
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)"
# 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)"
# 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;220" flac opus ogg oga mp3 m4a wav mid midi wma ac3 au aac spx)"
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;220" 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)
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;117" txt md adoc org rst html xhtml shtml htm)"
# Config files (brown)
LS_COLORS="${LS_COLORS}$(_gen_lscolor "38;5;130" 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)"
# Special cases
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"
export LS_COLORS
unfunction _gen_lscolor
# Host specific settings.
case ${HOST} in
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
[[ -f "${ZDOTDIR}"/secrets.zsh ]] && source "${ZDOTDIR}"/secrets.zsh
############################# 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
if [[ $(pgrep --uid ${EUID} ssh-agent)
&& $(pgrep --uid ${EUID} gpg-agent) ]]; then
# 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 \
&& [[ ! $(pgrep --uid ${EUID} ssh-agent) ]]; then
eval $(ssh-agent -t 16H 2> /dev/null)
fi
if command -v gpg-agent > /dev/null \
&& [[ ! $(pgrep --uid ${EUID} gpg-agent) ]]; then
eval $(gpg-agent --daemon --quiet --default-cache-ttl $((60*16)) \
--max-cache-ttl $((60*16)))
fi
fi
return 0
}