get back to split profile and env, shared has too many edge cases

This commit is contained in:
Nero 2021-08-03 20:14:38 +00:00
parent ae392d17e4
commit fcd82f9873
6 changed files with 94 additions and 114 deletions

134
env
View File

@ -1,118 +1,48 @@
# Config for setting up the environment across all sessions/applications
prepend_path() {
case ":${PATH}:" in
(*:${1}:*) ;;
(*) PATH="${1}:${PATH}" ;;
esac
}
# bash will source this file if its an non-interactive SSH login...
# so lets prevent execution for non-interactive shells
case "$-" in
(*i*) ;;
(*) return;;
esac
if test -n "$ENV" || test -n "$BASH_VERSION"; then
is_interactive() {
case "$-" in
(*i*) return 0;;
(*) return 1;;
esac
}
else
is_interactive() {
return 1
}
if [ -n "$BASH_VERSION" ]; then
shopt -s checkwinsize
elif [ -n "$ZSH_VERSION" ]; then
setopt PROMPT_SUBST autolist noautomenu
unsetopt menucomplete nomatch beep
fi
# This is for like, really crappy environments
[ -z "$USER" ] && export USER=$(whoami)
[ -z "$HOME" ] && eval "export HOME=~$USER"
[ -z "$LANG" ] && export LANG=en_US.UTF-8
# HOSTNAME is not in POSIX, but we will make it globally available
export HOSTNAME=$(uname -n)
# If $XDG_CONFIG_HOME is not set, read where the ~/.profile symlink points to
# and guess directory from that. This is relevant if the etc repo is checked
# out in a place different from ~/.config.
if [ -z "$XDG_CONFIG_HOME" ]; then
profile=$(readlink "$HOME/.profile")
case "$profile" in
('') ;;
(/*) export XDG_CONFIG_HOME="${profile%/*}" ;;
(*) export XDG_CONFIG_HOME="$HOME/${profile%/*}" ;;
esac
unset profile
fi
# Guess some directory where i can store sockets and pid files
# Like for ssh agent and connection multiplexing
if [ -z "$XDG_RUNTIME_DIR" ]; then
for i in "/run/user/$(id -u)" "$HOME/.run/$HOSTNAME" "/tmp/$USER-run"; do
if mkdir -m 0700 -p "$i" 2>/dev/null && test -w "$i"; then
export XDG_RUNTIME_DIR=$i
break
fi
export VISUAL=$(
for e in nano mcedit vi vim ed; do
hash "$e" >/dev/null 2>&1 && echo "$e" && break
done
fi
)
# Make interactive shells source this file again
test -z "$ENV" && export ENV="${XDG_CONFIG_HOME}/env"
# color support if available
case "$(ls --help 2>&1)" in
(*--color*) alias ls='ls --color=auto';;
esac
case "$(grep --help 2>&1)" in
(*--color*) alias grep='grep --color=auto';;
esac
# Default extra PATHs
prepend_path "${XDG_CONFIG_HOME}/bin"
prepend_path "${HOME}/.local/bin"
if is_interactive; then
if [ -n "$BASH_VERSION" ]; then
shopt -s checkwinsize
elif [ -n "$ZSH_VERSION" ]; then
setopt PROMPT_SUBST autolist noautomenu
unsetopt menucomplete nomatch beep
fi
export VISUAL=$(
for e in nano mcedit vi vim ed; do
hash "$e" >/dev/null 2>&1 && echo "$e" && break
done
)
case "$(ls --help 2>&1)" in
(*--color*) alias ls='ls --color=auto';;
esac
case "$(grep --help 2>&1)" in
(*--color*) alias grep='grep --color=auto';;
esac
alias feh='feh --output-dir "$HOME"'
fi
# feh stores 's' captures in $PWD per default, which i dont like
alias feh='feh --output-dir "$HOME"'
# short prompt with basename of PWD
if is_interactive; then
unset PS1
PS1='${PWD##*/}# '
# window title is written via stderr, so its not included in the output of the evaluation
# this avoids confusing shells about where the cursor currently is
case "$TERM" in
(screen*|tmux*|xterm*|rxvt-*) PS1="\$(printf '\033]0;%s\007' \"\${PWD##*/} - \${USER}@\${HOSTNAME}\" >&2)$PS1";;
esac
fi
unset PS1
PS1='${PWD##*/}# '
# window title is written via stderr, so its not included in the output of the evaluation
# this avoids confusing shells about where the cursor currently is
case "$TERM" in
(screen*|tmux*|xterm*|rxvt-*) PS1="\$(printf '\033]0;%s\007' \"\${PWD##*/} - \${USER}@\${HOSTNAME}\" >&2)$PS1";;
esac
# load drop-ins
for f in "$ENV".d/*; do
[ -e "$f" ] && . "$f"
done
unset f
# clear out shit
unset \
COLORTERM \
HUSHLOGIN \
TERMINAL \
VTE_VERSION \
WINDOWPATH \
XDG_SEAT \
XDG_SESSION_ID \
XDG_VTNR \
XDG_SESSION_CLASS \
XDG_SESSION_TYPE \
XTERM_LOCALE \
XTERM_SHELL \
XTERM_VERSION

View File

@ -1 +1 @@
is_interactive && gpg-connect-agent /bye >/dev/null 2>&1 && export GPG_TTY=$(tty)
gpg-connect-agent /bye >/dev/null 2>&1 && export GPG_TTY=$(tty)

View File

@ -1,3 +1,3 @@
if is_interactive && [ -n "$(ls /lib/modules 2>/dev/null)" ] && ! [ -d /lib/modules/$(uname -r) ]; then
if [ -n "$(ls /lib/modules 2>/dev/null)" ] && ! [ -d /lib/modules/$(uname -r) ]; then
echo "Kernel module disparity detected, reboot required"
fi

View File

@ -1,11 +1,9 @@
#!/bin/sh
if is_interactive; then
now="$(date +%s)"
for cert in ~/.ssh/*-cert.pub; do
now="$(date +%s)"
for cert in ~/.ssh/*-cert.pub; do
[ -e "$cert" ] || continue
strdate=$(ssh-keygen -L -f $cert|awk '/Valid/ {sub(/T/," ",$5);print($5)}')
awk -v c=${cert##*/} -v n=$now -v e=$(date -d "$strdate" "+%s") \
'BEGIN {d=(e-n) / (60*60*24); if (d<30) {printf("%s expires in %d days\n",c,d)}}'
done
unset now cert strdate
fi
'BEGIN {d=(e-n) / (60*60*24); if (d<30) {printf("%s expires in %d days\n",c,d)}}'
done
unset now cert strdate

View File

@ -14,15 +14,15 @@ sym() {
ls -l "$HOME/$1"
}
sym .profile env
sym .profile profile
case "$SHELL" in
(*/bash)
sym .bash_profile env
sym .bash_profile profile
sym .bashrc env
;;
(*/zsh)
sym .zprofile env
sym .zprofile profile
sym .zinitrc env
;;
esac

52
profile Normal file
View File

@ -0,0 +1,52 @@
# .profile for POSIX-conformant shells
# This is for really crappy environments
[ -z "$USER" ] && export USER=$(whoami)
[ -z "$HOME" ] && eval "export HOME=~$USER"
[ -z "$LANG" ] && export LANG=en_US.UTF-8
# HOSTNAME is not in POSIX, but we will make it globally available
export HOSTNAME=$(uname -n)
# If $XDG_CONFIG_HOME is not set, read where the ~/.profile symlink points to
# and guess directory from that. This is relevant if the etc repo is checked
# out in a place different from ~/.config.
if [ -z "$XDG_CONFIG_HOME" ]; then
profile=$(readlink "$HOME/.profile")
case "$profile" in
('') ;;
(/*) export XDG_CONFIG_HOME="${profile%/*}" ;;
(*) export XDG_CONFIG_HOME="$HOME/${profile%/*}" ;;
esac
unset profile
fi
# Guess some directory where i can store sockets and pid files
# Like for ssh agent and connection multiplexing
if [ -z "$XDG_RUNTIME_DIR" ]; then
for i in "/run/user/$(id -u)" "$HOME/.run/$HOSTNAME" "/tmp/$USER-run"; do
if mkdir -m 0700 -p "$i" 2>/dev/null && test -w "$i"; then
export XDG_RUNTIME_DIR=$i
break
fi
done
unset i
fi
# Make interactive shells source this file again
test -z "$ENV" && export ENV="${XDG_CONFIG_HOME}/env"
test -e "$ENV" || unset ENV
# Default extra PATHs
prepend_path() {
case ":${PATH}:" in
(*:${1}:*) ;;
(*) PATH="${1}:${PATH}" ;;
esac
}
prepend_path "${XDG_CONFIG_HOME}/bin"
prepend_path "${HOME}/.local/bin"
# If bash loads .profile, .bashrc gets skipped, even for interactive shells.
# This manually sources the shellrc to make sure prompt and such is loaded
[ -n "$BASH_VERSION" ] && . "$ENV"