Initial commit
This commit is contained in:
38
.shell_aliases
Normal file
38
.shell_aliases
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Turn on interactive mode for dangerous commands
|
||||||
|
alias cp='cp -iv'
|
||||||
|
alias mv='mv -iv'
|
||||||
|
alias rm='rm -iv'
|
||||||
|
|
||||||
|
# File sizes should always be human-readable
|
||||||
|
alias df='df -h'
|
||||||
|
alias du='du -h'
|
||||||
|
|
||||||
|
# Greps
|
||||||
|
alias egrep='egrep --color=auto' # show differences in colour
|
||||||
|
alias fgrep='fgrep --color=auto' # show differences in colour
|
||||||
|
|
||||||
|
# File Listing
|
||||||
|
# Must have lsd installed (https://github.com/lsd-rs/lsd)
|
||||||
|
alias ls='lsd '
|
||||||
|
alias l='ls -CF' # list with Columns
|
||||||
|
alias la='ls -CFA' # l with . and ..
|
||||||
|
alias ll='ls -l' # long list
|
||||||
|
alias lla='ls -al' # ll with . and ..
|
||||||
|
alias ls='ls -hF --color=tty' # classify files in colour
|
||||||
|
alias lls='ls -lh --sort=size --reverse'
|
||||||
|
alias llt='ls -l -t -r'
|
||||||
|
|
||||||
|
# Extras
|
||||||
|
alias ping='ping -c 5' # Stop pinging after 5 pings
|
||||||
|
alias vi='vim' # use vim instead of vi
|
||||||
|
alias less='less -r' # repaint screen
|
||||||
|
|
||||||
|
# Get Ext IP
|
||||||
|
alias extip='curl -s -4 icanhazip.com'
|
||||||
|
|
||||||
|
# Memory Pigs (top 10)
|
||||||
|
alias mempigs='ps aux | awk '\''{print $6/1024 " MB\t\t" $11 " " $12}'\'' | sort -n | tail -10'
|
||||||
|
|
||||||
|
# Edit files with vim/fzf
|
||||||
|
alias vfz='vim "`fzf`"'
|
||||||
|
alias vimf='vim "`fzf`"'
|
||||||
99
.shell_functions
Normal file
99
.shell_functions
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
# Shell Functions
|
||||||
|
|
||||||
|
# Shell note pad
|
||||||
|
note () {
|
||||||
|
# if file doesn't exist, create it
|
||||||
|
if [[ ! -f $HOME/.notes ]]; then
|
||||||
|
touch "$HOME/.notes"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! (($#)); then
|
||||||
|
# no arguments, print file
|
||||||
|
cat "$HOME/.notes"
|
||||||
|
elif [[ "$1" == "-c" ]]; then
|
||||||
|
# clear file
|
||||||
|
echo -n "Clear notes file? [Y/N] "
|
||||||
|
read replace
|
||||||
|
if [ "${replace}" = "Y" ] || [ "${replace}" = "y" ]; then
|
||||||
|
echo "Emptying notes file..."
|
||||||
|
printf "%s" > "$HOME/.notes"
|
||||||
|
echo "Done."
|
||||||
|
else
|
||||||
|
echo "Notes file preserved."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# add all arguments to file
|
||||||
|
echo -n $(date +"%F %T | ") >> "$HOME/.notes"
|
||||||
|
printf "%s\n" "$*" >> "$HOME/.notes"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# tar/gzip a directory
|
||||||
|
# I use this before 'rm -rf'ing a directory I think is useless
|
||||||
|
# if nothing breaks after a predetermined amount of time, then the tar file is safe to delete
|
||||||
|
tardir() {
|
||||||
|
#ensure $1 is a directory
|
||||||
|
if [ ! -d "${1}" ]; then
|
||||||
|
echo "$1 is not a directory. Aborting."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
#strip trailing slash
|
||||||
|
target="${1%/}"
|
||||||
|
echo "Dir size: $(du -hs ${target})"
|
||||||
|
tar czf "${target}".tar.gz "${target}"
|
||||||
|
echo "Archive size: $(du -hs ${target}.tar.gz)"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Replacement for 'for i in $(ls); do du -hs $i; done' that handles spaces
|
||||||
|
function dudir() {
|
||||||
|
if ! (($#)); then
|
||||||
|
dir=$(pwd)
|
||||||
|
else
|
||||||
|
dir="${1}"
|
||||||
|
fi
|
||||||
|
# redefine $IFS
|
||||||
|
o=$IFS
|
||||||
|
IFS=$(echo -en "\n\b")
|
||||||
|
for i in $(ls "${dir}"); do
|
||||||
|
du -hs "${i}"
|
||||||
|
done
|
||||||
|
# reset $IFS
|
||||||
|
IFS=$o
|
||||||
|
}
|
||||||
|
|
||||||
|
# HAHA! Weather in the terminal
|
||||||
|
weather() {
|
||||||
|
if [ $(command -v curl) ]; then
|
||||||
|
if ! (($#)); then
|
||||||
|
curl wttr.in/44113
|
||||||
|
else
|
||||||
|
curl wttr.in/$1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "curl not installed. Aborting."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Replaces "ps aux | grep <something>" with "psaux <something>". Shorter to type, more informational and doesn't include the command itself in the output.
|
||||||
|
psaux () { pgrep -f "$@" | xargs ps -fp 2>/dev/null; }
|
||||||
|
|
||||||
|
# mail a file
|
||||||
|
email() {
|
||||||
|
if ! (($#)); then
|
||||||
|
echo "USAGE: email {filename} {email-address}"
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
efile=${1}
|
||||||
|
eaddr=${2}
|
||||||
|
echo "See Attached" | mail -s "File: ${efile}" -a ${efile} ${2}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# git testmerge
|
||||||
|
testmerge() {
|
||||||
|
echo "git merge --no-commit --no-ff $1"
|
||||||
|
git merge --no-commit --no-ff $1
|
||||||
|
echo "git diff --cached"
|
||||||
|
git diff --cached
|
||||||
|
echo "'git merge --abort' when done"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user