dotfiles/functions

135 lines
2.3 KiB
Text
Raw Normal View History

2016-06-08 10:32:44 -04:00
function aws-profile {
if [ $# -eq 0 ]; then
echo Current AWS Profile: $AWS_DEFAULT_PROFILE
else
export AWS_DEFAULT_PROFILE=$1
export AWS_PROFILE=$1
2016-06-08 10:32:44 -04:00
fi
}
function fix-permissions {
find . -type d -print0 | xargs -0 chmod 0755
find . -type f -print0 | xargs -0 chmod 0644
}
2013-04-29 13:38:49 -04:00
function g {
if [[ $# > 0 ]]; then
git $@
else
git status
fi
}
2016-02-19 08:32:02 -05:00
function insert-sudo {
2013-05-28 23:32:51 -04:00
zle beginning-of-line
zle -U "sudo "
}
2017-08-30 21:18:04 -04:00
function true-colors {
awk 'BEGIN{
s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;
for (colnum = 0; colnum<77; colnum++) {
r = 255-(colnum*255/76);
g = (colnum*510/76);
b = (colnum*255/76);
if (g>255) g = 510-g;
printf "\033[48;2;%d;%d;%dm", r,g,b;
printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
printf "%s\033[0m", substr(s,colnum+1,1);
}
printf "\n";
}'
}
2013-05-28 22:25:28 -04:00
function port-forward {
if [ $# -lt 2 ]; then
echo Usage: port-forward HOST LOCAL_PORT \[REMOTE_PORT\]
else
ssh $1 -R ${3:-$2}":localhost:"$2 -g
fi
2013-05-28 22:25:28 -04:00
}
2014-08-21 05:56:28 -04:00
function gitignore-io {
2014-09-11 13:05:32 -04:00
curl https://www.gitignore.io/api/$@
2014-08-21 05:56:28 -04:00
}
2014-12-18 10:17:11 -05:00
function git-date-added {
if [ $# -eq 0 ]; then
echo Usage: git-date-added FILENAME
else
git log --format=%aD $1 | tail -1
fi
}
2016-02-05 13:52:00 -05:00
function run {
if [ $# -lt 2 ]; then
echo Usage: run NUMBER COMMAND
else
number=$1; shift
for i in `seq $number`; do
2020-02-27 09:47:16 -05:00
eval "$@"
2016-02-05 13:52:00 -05:00
done
fi
}
function npm-exec {
(PATH=$(npm bin):$PATH; eval $@;)
}
2017-01-14 12:18:34 -05:00
2018-05-30 09:14:30 -04:00
function password-generator {
if [ -x "$(command -v openssl)" ]; then
password=$(
openssl rand -base64 32 \
| head -c 32
)
else
password=$(
date +%s \
| sha256sum \
| base64 \
| head -c 32
)
fi
echo $password
}
function stopwatch {
date1=`date +%s`
while true; do
echo -ne "$(date -u --date @$((`date +%s` - $date1)) +%H:%M:%S)\r"
sleep 0.1
done
}
2020-01-21 10:03:18 -05:00
function test-rails {
if bundle exec rspec --help > /dev/null 2>&1; then
2020-01-22 11:33:00 -05:00
bundle exec rspec $@
2020-01-21 10:03:18 -05:00
else
2020-01-22 11:33:00 -05:00
bundle exec rails test $@
2020-01-21 10:03:18 -05:00
fi
}
2017-01-14 12:18:34 -05:00
function yarn-exec {
(PATH=$(yarn bin):$PATH; eval $@;)
}
function yarn-install-like-bundle {
if [ -f yarn.lock ]; then
yarn install --pure-lockfile
else
yarn install
fi
}
2020-09-10 10:09:35 -04:00
function ag-count {
if [ $# -lt 1 ]; then
echo Usage: ag-count SEARCHTERM
else
searchterm=$1; shift
ag --stats $searchterm | tail -n5
fi
}