Files
dots/bash/.bashrc
2022-08-20 10:38:42 -05:00

199 lines
4.9 KiB
Bash

# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
#export SYSTEMD_PAGER=
#pager setup
#-C faster reprints
#-F auto quit if less than 1 screen
#-M more status
#-I case insensitive
#-j 5 show X lines above search for context
#-R fix ansi esc sequences
## 4 - right/left four chars
export LESS='-C -M -j 3 -R -# 2'
### User specific aliases and functions
# before you remove, you can unalias with: \<command>
alias l.='ls -lh --time-style=long-iso --color' 2>/dev/null
alias l='ls -lh --color --time-style=long'
alias ll='ls -lAh --color --time-style=long'
alias lsd='l -d */'
alias p='ping'
alias ip='ip -c'
#alias s='sudo $(history -p !!)'
alias s='sudo'
alias df='sudo df -hT -x tmpfs -x devtmpfs'
alias rsync='rsync --progress'
alias lg='ll | grep -i $0'
# allows alias expansion after sudo, eg: sudo l
# bash man page, "last char of alias value is space or tab..."
alias sudo='sudo '
#bind 'set completion-ignore-case on'
set bell-style none
## function and alias for short find
short_find() {
find ./ -iname "*${1}*"
}
alias f=short_find
# enable va-api in firefox
export MOZ_X11_EGL=1
#not sure why fedora doesnt set this or what it might break but here we go
export XDG_CONFIG_HOME=$HOME/.config
# make tab after cd only complete using dir names
complete -d cd
#golang stuff
export GOPATH=$HOME/gopath
export PATH=$GOPATH:$GOPATH/bin:$PATH
# use vimx if available (for clipboard support)
if [ -f "/usr/bin/vimx" ]; then
export EDITOR=/usr/bin/vimx
alias vim=/usr/bin/vimx
else
export EDITOR=/usr/bin/vim
fi
# so stupid, systemd ignores EDITOR and requires its own env variable
# just set it to whatever editor is
export SYSTEMD_EDITOR=$EDITOR
### set nnn options
# set detailed mode by default, a for auto FIFO
export NNN_OPTS='da'
export NNN_PLUG='p:preview-tui;v:preview-tabbed;B:rsynccp'
# use xdg-open to handle more filetypes, correctly
export NNN_FALLBACK_OPENER=xdg-open
# nnn bookmarks, format of key:path
export NNN_BMS='d:~/Downloads;h:~;m:/s/movies;t:/s/tv'
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
#ctrl-x, ctrl-e to launch $EDITOR (vim)
#bind -m vi-insert '"\C-x\C-e": edit-and-execute-command'
#fix clear screen in vi mode
#bind -m vi-insert "\C-l":clear-screen
# HISTORY
#add date/time to history
export HISTTIMEFORMAT="%F %T: "
export HISTSIZE=100000
export HISTFILESIZE=1000000
#if tty -s; then
if [ -t 1 ]; then
export PS1="\[$(tput bold)\]\[$(tput setaf 4)\][\u@\h \W]\\$ \[$(tput sgr0)\]"
fi
if [ ! -z "$VIRTUAL_ENV" ]; then
#export PS1="[$(basename "$VIRTUAL_ENV")] \[\u@\h \W]\\$"
export PS1="[$(basename "$VIRTUAL_ENV")] $PS1"
fi
# fedoras stupid command-not-found shit
unset command_not_found_handle
if [ -f /usr/share/fzf/shell/key-bindings.bash ]; then
source /usr/share/fzf/shell/key-bindings.bash
fi
#this is a stopwatch function, call with: $ stopwatch
stopwatch () {
date1=`date +%s`; while true; do echo -ne "$(date -u --date @$((`date +%s` - $date1)) +%H:%M:%S)\r"; done
}
timer() {
start="$(( $(date '+%s') + $1))"
while [ $start -ge $(date +%s) ]; do
time="$(( $start - $(date +%s) ))"
printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)"
sleep 0.1
done
notify-send "Timer Finished" "Timer Finished - $1 seconds elapsed"
}
n ()
{
# Block nesting of nnn in subshells
if [ -n $NNNLVL ] && [ "${NNNLVL:-0}" -ge 1 ]; then
echo "nnn is already running"
return
fi
# The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
# To cd on quit only on ^G, remove the "export" as in:
# NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
# NOTE: NNN_TMPFILE is fixed, should not be modified
export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
# Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
# stty start undef
# stty stop undef
# stty lwrap undef
# stty lnext undef
nnn "$@"
if [ -f "$NNN_TMPFILE" ]; then
. "$NNN_TMPFILE"
rm -f "$NNN_TMPFILE" > /dev/null
fi
}
ex() {
local c e i
(($#)) || return
for i; do
c=''
e=1
if [ $# -eq 0 ]; then
echo "No file specified"
exit
fi
if [[ ! -r $i ]]; then
echo "$0: file is unreadable: \`$i'" >&2
continue
fi
case $i in
*.tar) c=(tar xf);;
*.7z) c=(7z x);;
*.Z) c=(uncompress);;
*.bz2) c=(bunzip2);;
*.exe) c=(cabextract);;
*.gz) c=(gunzip);;
*.rar) c=(unrar x);;
*.xz) c=(unxz);;
*.zip) c=(unzip);;
*) echo "$0: unrecognized file extension: \`$i'" >&2
continue;;
esac
command "${c[@]}" "$i"
((e = e || $?))
done
return "$e"
}
# turn off incredibly annoying bell
#xset b off