Skip to content

Instantly share code, notes, and snippets.

@jarfil
Last active August 28, 2021 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarfil/da3a5a45bf10e1803d18 to your computer and use it in GitHub Desktop.
Save jarfil/da3a5a45bf10e1803d18 to your computer and use it in GitHub Desktop.
Common personalized dircolors and aliases
# to be called from ~/.bashrc or similar
# don't apply changes if not logging in from given IP
### IP restriction
#if [ "${SSH_CLIENT//`dig +short fractal.jarfil.net`/}" != "$SSH_CLIENT" ] ; then
export PS1='[$(
if [ "a${USER:-${USERNAME:-$(whoami)}}" == aroot ] ; then
echo "\[\e[01;31m\]"
elif [[ "${GROUPS[@]}" =~ (^| )(114|544)( |$) ]] ; then
echo "\[\e[01;35m\]"
fi
)\u\[\e[0m\]@$(
if [ ! -z "$REMOTEUSER" ] || [ ! -z "$SSH_TTY" ] ; then
echo "\[\e[01;33m\]"
else
echo "\[\e[0m\]"
fi
)\h\[\e[0m\] \W]\$ '
#'" (fix for vim syntax highlight)
# xterm/putty window title
# https://unix.stackexchange.com/questions/40830/fix-terminal-title-after-ssh-remote-logging-to-another-machine
PS1='\[\e]2;\u@\H:\w\a\]'"$PS1"
# avoid adding twice
if [ "x${PATH/~\/bin/}x" = "x${PATH}x" ] ; then
export PATH="~/bin:$PATH"
fi
export LS_OPTIONS='--color=auto'
eval `dircolors`
alias cd..='cd ..'
alias cls='clear'
alias cp='cp -i'
alias d='ls'
alias df='df -h -x supermount'
alias du='du -h'
alias dus='du -csx -B1 --exclude=. --exclude=.. $* -- * .* | sort -n'
alias dusa='du -bs `ls -a | grep -v "\.\."` | sort -n'
alias dud='du -Lbcs "$@"'
alias l='ls $LS_OPTIONS -l'
alias lh='ls $LS_OPTIONS -l -a -d .*'
alias la='ls $LS_OPTIONS -l -a'
alias ll='ls $LS_OPTIONS -l'
alias ls='ls $LS_OPTIONS'
alias lsd='ls $LS_OPTIONS -d -l */'
alias md='mkdir'
alias mv='mv -i'
alias p='cd -'
alias rd='rmdir'
alias rm='rm -i'
alias s='cd ..'
#alias mailq='postqueue -p'
# per-directory file count + sort
alias filc='for f in `find -maxdepth 1 -type d` ; do echo `find $f 2>/dev/null | wc -l 2>/dev/null` $f ; done | sort -n'
# list symbolic link targets
alias lL='ls -l $* | grep -- "->" | cut -d ">" -f 2 | cut -d " " -f 2-'
# rmdir recursive (only empty dirs)
alias rdr='rmdir `find $* -type d | sort -r`'
# recursive size list
alias findsiz='find -printf "%s\t%p\n"'
# date format
alias datef='date -u +%Y%m%d-%H%M%S'
# thousands separator
# https://unix.stackexchange.com/questions/113795/add-thousands-separator-in-a-number
alias thsep="sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'"
# grep ps output keeping headers
psgrep() { awk "NR==1 { print; next } /$1/ && ! /awk-$!/ {print}"; }
# docker
alias docker-here='docker run -it --rm -v `pwd`:/mnt ubuntu bash'
# ssh-agent
# http://superuser.com/a/886510/138584
# attempt to connect to a running agent - cache SSH_AUTH_SOCK in ~/.ssh/
sagent()
{
[ -S "$SSH_AUTH_SOCK" ] || export SSH_AUTH_SOCK="$(< ~/.ssh/ssh-agent.env)"
# if cached agent socket is invalid, start a new one
[ -S "$SSH_AUTH_SOCK" ] || {
eval "$(ssh-agent)"
ssh-add -k ~/.ssh/id_rsa
echo "$SSH_AUTH_SOCK" > ~/.ssh/ssh-agent.env
}
}
### CYGWIN
if [ "$OSTYPE" == "cygwin" ] ; then
# https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks
export CYGWIN=winsymlinks:native
# https://cygwin.com/cygwin-ug-net/using-effectively.html
# https://scotch.io/tutorials/open-sublime-text-from-the-command-line-using-subl-exe-windows
# https://stackoverflow.com/questions/7131670/make-bash-alias-that-takes-parameter
sublimetext() {
"C:/Program Files/Sublime Text/subl.exe" "$(cygpath -pw "$1")" $*
}
alias vis='sublimetext'
alias diff='diff --strip-trailing-cr'
fi
### end CYGWIN
#fi
### end IP restriction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment