dot_testing/.config/bash/bashrc

101 lines
2.0 KiB
Bash

#!/bin/bash
# if not interactive, don't do anything
[ -z "$PS1" ] && return
# some housekeeping
alias ls="ls --color=auto"
alias ll="ls -lah --color=auto"
function cd() {
builtin cd "$@" && ls --color=auto
}
# history
HISTCONTROL=ignorespace:ignoredups:erasedups
HISTFILESIZE=9999999999
HISTSIZE=9999999999
# bash specific settings
set -o vi # vim mode
shopt -s autocd
shopt -s cmdhist
shopt -s histreedit
shopt -s histappend
shopt -s histverify
PS1="\w\$ "
if [ -n "$IN_NIX_SHELL" ]; then
NIX_SHELL_PS1="nix:"
fi
if [ "$USER" = "root" ]; then
USER_PREFIX="\[\033[41m\]root:\[\033[0;0m\]"
elif [ "$USER" != "usr" ]; then
USER_PREFIX="$USER:"
fi
# hostname shenanigans
case "$HOSTNAME" in
"aristotle")
PS1="$USER_PREFIX\[\033[36;1m\]${NIX_SHELL_PS1}arist:$PS1\[\033[0;0m\]"
;;
"copernicus")
PS1="$USER_PREFIX\[\033[97;1m\]${NIX_SHELL_PS1}coper:$PS1\[\033[0;0m\]"
;;
"x230t")
PS1="$USER_PREFIX\[\033[93;1m\]${NIX_SHELL_PS1}x230t:$PS1\[\033[0;0m\]"
;;
"mlg")
PS1="$USER_PREFIX\[\033[94;1m\]${NIX_SHELL_PS1}mlg:$PS1\[\033[0;0m\]"
;;
"netbox")
PS1="$USER_PREFIX\[\033[95;1m\]${NIX_SHELL_PS1}net:$PS1\[\033[0;0m\]"
;;
*)
PS1="$USER_PREFIX\[\033[96;1m\]${NIX_SHELL_PS1}unk:$PS1\[\033[0;0m\]"
;;
esac
repos() {
sel="$(ls ~/git | fzy | awk '{print "/home/usr/git/"$1}')"
[ "$?" -eq 1 ] && exit
cd "$sel"
}
hist() {
res=$(cat ~/.config/bash/hist | \
sort | \
uniq | \
shuf | \
fzy)
[ -n "$res" ] && $($res)
}
search() {
if [ "$1" = '-a' ]; then
res=$(find /home/usr/ /home/usr/doc/ \
-mindepth 1 \
-not -path '*/.*' \
-not -path './Mail/*' \
-not -path './vdir/*' \
-not -path '*venv*' \
-not -path '*node_modules*' \
-not -path '*__pycache__*' \
-type d | cut -c 11- | fzy)
else
res=$(find $(pwd) \
-mindepth 1 \
-not -path '*/.*' \
-not -path './Mail/*' \
-not -path './vdir/*' \
-not -path '*venv*' \
-not -path '*node_modules*' \
-not -path '*__pycache__*' \
-type d | cut -c 11- | fzy)
fi
[ -n "$res" ] && cd /home/usr/"$res"
}