323 lines
9.7 KiB
Bash
Executable File
323 lines
9.7 KiB
Bash
Executable File
unset MAILCHECK || true
|
|
|
|
if [[ -d "${HOME}/.yadm/share/private" ]]; then
|
|
source .local/share/yadm/private/zsh.d/care-env.sh
|
|
fi
|
|
|
|
if [[ -n "${CARE_ENV}" ]]; then
|
|
ENV="care.com"
|
|
elif [[ -d "/meta" || -d "/sdf" ]]; then
|
|
ENV="sdf.org"
|
|
else
|
|
ENV="sudo.is"
|
|
# Might need better handling for the systems where dotfiles are not managed by yadm
|
|
if [[ ! -d "${HOME}/.local/share/yadm/repo.git" && -d "/srv/dotfiles" ]]; then
|
|
SUDO_ENV="server"
|
|
else
|
|
SUDO_ENV="shell"
|
|
fi
|
|
fi
|
|
|
|
# This might need different handling on systems without yadm
|
|
ZSH_CUSTOM="${HOME}/.zsh.d"
|
|
OMZSH="${HOME}/.local/share/yadm/ohmyzsh"
|
|
|
|
SSH_AGENT_ENVFILE="${HOME}/.agent-ssh.env"
|
|
|
|
# the variable that oh-my-zsh expects
|
|
ZSH=$OMZSH
|
|
|
|
# nice omzsh themes:
|
|
# * jreese
|
|
# * gentoo
|
|
# * alanpeabody (doesnt show full path and color blends with background)
|
|
|
|
color_red='\033[0;31m'
|
|
color_red_light='\033[1;31m'
|
|
color_green='\033[0;32m'
|
|
color_green_light='\033[1;32m'
|
|
color_orange='\033[0;33m'
|
|
color_yellow='\033[1;33m'
|
|
color_blue='\033[0;34m'
|
|
color_purple='\033[0;35m'
|
|
color_cyan='\033[0;36m'
|
|
color_purple='\033[0;35m'
|
|
|
|
color_nc='\033[0m'
|
|
|
|
export TZ="Europe/Berlin"
|
|
export LC_ALL=en_US.UTF-8
|
|
export LANG=en_US.UTF-8
|
|
export PATH=$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:$PATH
|
|
export GPG_TTY=$(tty)
|
|
|
|
|
|
# oh-my-zsh will set this var otherwise, causing e.g. awscli to display everything in a pager
|
|
# https://superuser.com/questions/1698521/zsh-keep-all-command-outputs-on-terminal-screen
|
|
export PAGER=""
|
|
|
|
# in case dotnet happens to be installed, disable the telemetry
|
|
export DOTNET_CLI_TELEMETRY_OPTOUT=true
|
|
|
|
setopt shwordsplit # for loops over "space separated strings" like bash
|
|
setopt append_history # append rather then overwrite
|
|
setopt extended_history # save timestamp
|
|
setopt inc_append_history # add history immediately after typing a command
|
|
|
|
alias less="less -R"
|
|
alias dmesg="dmesg --human --color=always -T"
|
|
alias nomail="echo 'd *' | mail -N"
|
|
# from jbs
|
|
alias json2yaml="python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, default_flow_style=False)'"
|
|
alias j2y="json2yaml"
|
|
|
|
export EDITOR="vim"
|
|
|
|
# in submodules, .git is a file:
|
|
# $ cat ${OMZSH}/.git
|
|
# gitdir: ../../.git/modules/zsh/.oh-my-zsh
|
|
#if [[ -d "${OMZSH}" && ! -f "${OMZSH}/.git" ]]; then
|
|
# echo "oh-my-zsh submodule needs to be initialized"
|
|
# git -C $DOTFILES submodule update --init --recursive
|
|
$fi
|
|
|
|
if [[ "$ENV" == "care.com" ]]; then
|
|
ENV="care.com"
|
|
ZSH_THEME="jreese2"
|
|
|
|
source ${HOME}/.local/share/yadm/private/zsh.d/caredotcom.sh
|
|
|
|
# set colors for jreese2
|
|
export PROMPT_HOSTNAME=$CARE_ENV
|
|
export PROMPT_COLOR_HOSTNAME=green
|
|
export PROMPT_COLOR=blue
|
|
ENV_COLOR=$color_green
|
|
|
|
alias noflag="unset RPROMPT"
|
|
alias emacs='~/.local/emacs/bin/emacs -nw'
|
|
alias emacsclient='~/.local/emacs/bin/emacsclient -nw'
|
|
|
|
powerup () {
|
|
/usr/local/bin/powerup $* > ${HOME}/.aws/powerup.env
|
|
source ${HOME}/.aws/powerup.env
|
|
}
|
|
|
|
elif [[ -d "/meta" || -d "/sdf" ]]; then
|
|
ENV="sdf.org"
|
|
ZSH_THEME="jreese2"
|
|
|
|
export PROMPT_COLOR_HOSTNAME=yellow
|
|
export PROMPT_COLOR=blue
|
|
ENV_COLOR=$color_orange
|
|
else
|
|
ENV="sudo.is"
|
|
if [[ "$SUDO_ENV" == "server" ]]; then
|
|
PROMPT_COLOR=blue
|
|
ZSH_THEME="gentoo"
|
|
else
|
|
if [[ "${OSTYPE}" == "darwin"* ]]; then
|
|
PROMPT_COLOR="magenta"
|
|
fi
|
|
ZSH_THEME="jreese2"
|
|
fi
|
|
if [[ -d "$HOME/.cargo" ]]; then
|
|
export PATH="$HOME/.cargo/bin:$PATH"
|
|
fi
|
|
|
|
alias dl-mp3='yt-dlp --extract-audio --embed-thumbnail --embed-metadata --audio-quality 320k --audio-format "mp3" --format "ba"'
|
|
alias dl-audio='yt-dlp --extract-audio --embed-thumbnail --embed-metadata --audio-quality "best" --audio-format "best" --format "ba"'
|
|
alias dl-audio-keep='yt-dlp --keep-video --extract-audio --embed-thumbnail --embed-metadata --audio-quality "best" --audio-format "best" --format "ba"'
|
|
|
|
alias dockps='docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"'
|
|
alias nc-occ='docker exec -it --user www-data nextcloud php occ'
|
|
alias codec='ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1'
|
|
alias emacs="emacs -nw"
|
|
alias emacsclient="emacsclient -nw"
|
|
fi
|
|
motd_env="${color_purple}env${color_nc} ${ENV_COLOR}${ENV}${color_nc}"
|
|
|
|
# safely load ssh-agent without eval
|
|
if [[ -f "${SSH_AGENT_ENVFILE}" ]]; then
|
|
chmod 700 $SSH_AGENT_ENVFILE
|
|
# exec $(cat $SSH_AGENT_ENVFILE)
|
|
source $SSH_AGENT_ENVFILE > /dev/null
|
|
export SSH_AUTH_SOCK
|
|
export SSH_AGENT_PID
|
|
fi
|
|
|
|
# -S : is a socket file
|
|
if [[ -S ${SSH_AUTH_SOCK} && -n "${SSH_AGENT_PID}" ]] && `ps -p "${SSH_AGENT_PID}" >/dev/null`; then
|
|
motd_ssh_agent=$(while IFS= read -r line; do
|
|
echo -e "${color_purple}ssh-agent${color_nc} ${color_orange}${line}${color_nc}"
|
|
done) <<< $(ssh-add -l | awk -F' ' '{ print $3 }')
|
|
elif [[ -f $SSH_AGENT_ENVFILE ]]; then
|
|
rm -v $SSH_AGENT_ENVFILE
|
|
fi
|
|
|
|
|
|
# gpg-agent: this probably isnt needed
|
|
# if [[ -f ~/.gnupg/agent-info.env ]]; then
|
|
# eval $(cat ${HOME}/.gnupg/agent-info.env)
|
|
# fi
|
|
|
|
|
|
if [[ "${OMZSH_DISABLED}" != "true" ]]; then
|
|
plugins=(
|
|
# emacs # open files via emacsclient everywhere
|
|
ansible
|
|
colored-man-pages
|
|
colorize
|
|
docker # auto complete
|
|
git
|
|
#gpg-agent
|
|
nmap
|
|
#pep8
|
|
safe-paste
|
|
urltools # urlencode and urldecode
|
|
)
|
|
if [[ $system = "Darwin" ]]; then
|
|
plugins+=(osx brew)
|
|
fi
|
|
source $ZSH/oh-my-zsh.sh
|
|
|
|
# remove unwanted aliases set by ohmzh/plugins
|
|
unalias a 2>/dev/null
|
|
else
|
|
# on a system without oh-my-zsh (f.ex. non util/control nodes)
|
|
# set some basic settings
|
|
SAVEHIST=10000
|
|
HISTFILE=~/.zsh_history
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## these are almost never used
|
|
#alias stripcomment='grep -v "^#" | grep -v "^[[:space:]]*#" | grep -v "^$"'
|
|
#alias prettyjson='python -m json.tool'
|
|
#alias cleangit='git branch | grep -v "master" | xargs git branch -D'
|
|
|
|
fixssh() {
|
|
if [[ -x "$(command -v tmux)" ]]; then
|
|
eval $(tmux show-env | sed -n 's/^\(SSH_[^=]*\)=\(.*\)/export \1="\2"/p')
|
|
else
|
|
echo "fixssh doesnt do anything without tmux"
|
|
fi
|
|
}
|
|
|
|
system=$(uname -s)
|
|
case $system in
|
|
Darwin)
|
|
alias speed="sudo pmset -a disablesleep 1"
|
|
alias weed="sudo pmset -a disablesleep 0"
|
|
# defaulting to brew-installed python3
|
|
export PATH="$HOME/Library/Python/3.9/bin:$PATH"
|
|
;;
|
|
esac
|
|
|
|
# Set to this to use case-sensitive completion
|
|
# CASE_SENSITIVE="true"
|
|
|
|
# Uncomment this to disable bi-weekly auto-update checks
|
|
# DISABLE_AUTO_UPDATE="true"
|
|
|
|
# Uncomment to change how often before auto-updates occur? (in days)
|
|
# export UPDATE_ZSH_DAYS=13
|
|
|
|
# Uncomment following line if you want to disable colors in ls
|
|
# DISABLE_LS_COLORS="true"
|
|
|
|
# Uncomment following line if you want to disable autosetting terminal title.
|
|
# DISABLE_AUTO_TITLE="true"
|
|
|
|
# Uncomment following line if you want to disable command autocorrection
|
|
# DISABLE_CORRECTION="true"
|
|
|
|
# Uncomment following line if you want red dots to be displayed while waiting for completion
|
|
# COMPLETION_WAITING_DOTS="true"
|
|
|
|
# Uncomment following line if you want to disable marking untracked files under
|
|
# VCS as dirty. This makes repository status check for large repositories much,
|
|
# much faster.
|
|
# DISABLE_UNTRACKED_FILES_DIRTY="true"
|
|
|
|
|
|
|
|
if [[ $TERM == "dumb" ]]; then
|
|
# if Tramp in Emacs, set a dumber PS1 that tramp will understand
|
|
PS1='> '
|
|
# for tramp to not hang, need the following. cf:
|
|
# http://www.emacswiki.org/emacs/TrampMode
|
|
unsetopt zle
|
|
unsetopt prompt_cr
|
|
unsetopt prompt_subst
|
|
unfunction precmd
|
|
unfunction preexec
|
|
else
|
|
# otherwise default to xterm-256color
|
|
export TERM=xterm-256color
|
|
echo -e "$motd_env"
|
|
if [[ -n "${SSH_CLIENT}" ]]; then
|
|
echo -ne "${color_purple}from ipv4${color_nc} ${color_cyan}"
|
|
echo -n $SSH_CLIENT | awk '{ print $1 }'
|
|
echo -e "${color_nc}"
|
|
fi
|
|
if [[ -n "$motd_ssh_agent" ]]; then
|
|
echo -e "$motd_ssh_agent"
|
|
fi
|
|
fi
|
|
|
|
if [[ -x $(which hostname) && "$OSTYPE" != "darwin"* ]]; then
|
|
case $(hostname --fqdn) in
|
|
sensor-*.s21.sudo.is|ber1.sudo.is)
|
|
PROMPT="🌡️ $PROMPT"
|
|
;;
|
|
*)
|
|
esac
|
|
fi
|
|
|
|
# if [[ -d "${HOME}/.zsh.d" ]]; then
|
|
# echo "WARNING: ${HOME}/.zsh.d still exists on this system"
|
|
# fi
|
|
|
|
|
|
# Automatically attach to the tmux session on SSH
|
|
vterm_printf(){
|
|
if [[ -n "$TMUX" ]]; then
|
|
# Tell tmux to pass the escape sequences through
|
|
# (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324)
|
|
printf "\ePtmux;\e\e]%s\007\e\\" "$1"
|
|
elif [[ "${TERM%%-*}" == "screen" ]]; then
|
|
# GNU screen (screen, screen-256color, screen-256color-bce)
|
|
printf "\eP\e]%s\007\e\\" "$1"
|
|
else
|
|
printf "\e]%s\e\\" "$1"
|
|
fi
|
|
}
|
|
if [[ -x "$(command -v tmux)" && "$SSH_TMUX_AUTO_ATTACH" == "true" ]]; then
|
|
if [[ -z "$TMUX" && "$SSH_CONNECTION" != "" ]]; then
|
|
tmux attach-session -t ssh || tmux new-session -s ssh
|
|
fi
|
|
fi
|
|
|
|
|
|
# alias sibprod='(mkdir -p ~/deadprod && cd ~/deadprod && rsync --exclude="__pycache__" --exclude="*egg-info" -av ber0:projects/sudoisbot . ) && cd ~/deadprod/sudoisbot && poetry run sudoisbot'
|
|
# alias sib="(cd ~ && rsync --exclude="__pycache__" -av ber0:projects/sudoisbot .) && cd ~/sudoisbot && poetry run sudoisbot"
|
|
cast() {
|
|
webhook_url=$(cat ~/.hass_webhook_url | tr -d '\n')
|
|
cast_url=$1
|
|
curl -s -i -X POST -d "url=${cast_url}" $webhook_url | head -n 1
|
|
}
|
|
|
|
castnr() {
|
|
url_nr=$1
|
|
cast $(sed -n "${url_nr}p" ~/.cast_urls.txt)
|
|
}
|
|
|
|
# https://github.com/NixOS/nix/issues/7880#issuecomment-1750399157
|
|
if [[ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]]; then
|
|
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
|
|
fi
|