Skip to content

Instantly share code, notes, and snippets.

@packetchef
Created July 21, 2020 23:35
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 packetchef/0252c1cc909b3d70808246b8dbe8e17a to your computer and use it in GitHub Desktop.
Save packetchef/0252c1cc909b3d70808246b8dbe8e17a to your computer and use it in GitHub Desktop.
My sweet bash profile for macOS
# Simple PS1 - we don't actually use this because we redefine PS1 later
if [ -n "$PS1" ]; then PS1='\h:\w \u\$ '; fi
# Make bash check it's window size after a process completes
shopt -s checkwinsize
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:~/bin:/usr/local/go/bin"
export PATH
export GOPATH=$HOME/src/go
# Gawd I hate zsh
export BASH_SILENCE_DEPRECATION_WARNING=1
# Handy aliases
alias shred='/usr/bin/srm'
alias ls='ls -Gh'
alias grep='grep --color -E'
alias sed='sed -E'
alias vi=/usr/bin/vim
alias vim=/usr/bin/vim
# Why does macOS Catalina still ship with Python 2.7 by default..
alias python='python3'
alias youtube-dl='youtube-dl --merge-output-format mp4'
# Now we get fancy
# Print working directory after a cd.
cd() {
if [[ $@ == '-' ]]; then
builtin cd "$@" > /dev/null # We'll handle pwd.
else
builtin cd "$@"
fi
echo -e " \033[1;30m"`pwd`"\033[0m"
}
############################################
# Modified from emilis bash prompt script
# from https://github.com/emilis/emilis-config/blob/master/.bash_ps1
#
# Modified for Mac OS X by @corndogcomputer
###########################################
# Fill with minuses
# (this is recalculated every time the prompt is shown in function prompt_command):
fill="--- "
reset_style='\[\033[00m\]'
status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color
prompt_style=$reset_style
command_style=$reset_style'\[\033[1;29m\]' # bold black
# Prompt variable:
PS1="$status_style"'$fill \t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\w\$'"$command_style "
# Reset color for command output
# (this one is invoked every time before a command is executed):
trap 'echo -ne "\033[00m"' DEBUG
function prompt_command {
# create a $fill of all screen width minus the time string and a space:
let fillsize=${COLUMNS}-9
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="-${fill}" # fill with underscores to work on
let fillsize=${fillsize}-1
done
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
bname=`basename "${PWD/$HOME/~}"`
echo -ne "\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
;;
*)
;;
esac
}
PROMPT_COMMAND=prompt_command
# Protect ourselves from some self-inflicted hamr
function safe_rm() {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]]; then :
else
local dst=${path##*/}
# append the time if necessary
while [ -e ~/.Trash/"$dst" ]; do
dst="$dst "$(date +%H-%M-%S)
done
mv "$path" ~/.Trash/"$dst"
fi
done
}
# This is redundant with adding -G to the ls alias
# from http://theappleblog.com/2009/03/26/terminal-tips-using-the-command-line-with-style/
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
# Simple little function for encrypting files with AES CBC
function encrypt {
if [ "$1" = "" ]; then
echo "Usage: encrypt filename"
elif [ -d "$1" ]; then
echo ""$1" is a directory"
elif [ -L "$1" ]; then
echo ""$1" is a symbolic link"
elif ! [ -r "$1" ]; then
echo ""$1" is not readable"
else
/usr/bin/openssl aes-256-cbc -salt -in "$1" -out "$1".aes
if [ $? -eq 0 ] ; then
echo "encryted file: "$1".aes"
fi
fi
}
function decrypt {
if [ "$1" = "" ] || [ "${1##*.}" != aes ]; then
echo "Usage: decrypt filename.aes"
else
/usr/bin/openssl aes-256-cbc -d -salt -in "$1" -out "${1%.aes}" 2>/dev/null
if [ $? -eq 0 ] ; then
echo "decryted file: ${1%.aes}"
else
/bin/rm "${1%.aes}"
echo -e "bad decrypt, possible incorrect password \n(${1%.aes} deleted)"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment