Skip to content

Instantly share code, notes, and snippets.

@justin808
Created November 15, 2014 20:13
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 justin808/bdef67f37c2cbdba898a to your computer and use it in GitHub Desktop.
Save justin808/bdef67f37c2cbdba898a to your computer and use it in GitHub Desktop.
Some utility functions that my other zsh gists use
# Generic Utilities
using_port() {
ps -p $(lsof -i:$1 -Fp | cut -c 2-)
}
most_used() {
history | awk '{a[$4]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head -20
}
echoRun() {
START=$(date +%s)
echo "> $1"
eval time $1
END=$(date +%s)
DIFF=$(( $END - $START ))
echo "It took $DIFF seconds"
}
sanitize() {
echo $1 | tr ": /." "-" | tr -d ",'\""
}
# history grep tail
hgt() {
fc -l 1 | grep -i --color=auto $1 | tail -n 40
}
funcs() {
# With cheating by looking at the _functions completion function, I'm able to
# answer your question:
#
# The functions are stored in an associative array functions, so to get only the
# funtion names (k flag for keys) in alphabetical order (o flag for ordering)
# then use which <func_name> to see the definition of that function
print -l ${(ok)functions}
}
marked() {
if [[ -f $1 ]]; then
open -a marked.app $1
echo found file $1
else
open -a marked.app
echo no file existing $1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment