dotfiles/zsh/.functions

170 lines
3 KiB
Text
Raw Normal View History

2021-11-02 20:14:26 -04:00
function ag-count {
if [ $# -lt 1 ]; then
echo Usage: ag-count SEARCHTERM
2016-06-08 10:32:44 -04:00
else
2021-11-02 20:14:26 -04:00
searchterm=$1; shift
ag --stats $searchterm | tail -n5
2016-06-08 10:32:44 -04:00
fi
}
function aet-bin-exec {
local readonly script=$1; shift
./aet-bin/$script $@
}
2021-11-02 20:14:26 -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
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
}
2021-11-02 20:14:26 -04:00
function git-branch-cleanup {
if [ $# -eq 0 ]; then
branch=master
else
2021-11-02 20:14:26 -04:00
branch=$1
fi
2021-11-02 20:14:26 -04:00
git branch --merged $branch | grep -v $branch | xargs git branch -d
2013-05-28 22:25:28 -04:00
}
2021-11-02 20:14:26 -04:00
function git-branch-delete-merged {
git branch --merged \
| grep -v "\*" \
| grep -v master \
| grep -v staging \
| grep -v development \
| xargs -n 1 git branch -d
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
2021-11-02 20:14:26 -04:00
function gitignore-io {
curl https://www.gitignore.io/api/$@
}
2016-02-05 13:52:00 -05:00
2021-11-02 20:14:26 -04:00
function insert-sudo {
zle beginning-of-line
zle -U "sudo "
2016-02-05 13:52:00 -05:00
}
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
}
2021-11-02 20:14:26 -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
}
function run {
if [ $# -lt 2 ]; then
echo Usage: run NUMBER COMMAND
else
number=$1; shift
for i in `seq $number`; do
eval "$@"
done
fi
}
2018-05-30 09:14:30 -04:00
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
2021-06-18 22:10:46 -04:00
if [ -d spec ]; then
bundle exec rspec $@
else
ruby *_test.rb
fi
elif bundle exec rails version > /dev/null 2>&1; then
2020-01-22 11:33:00 -05:00
bundle exec rails test $@
2021-06-18 22:10:46 -04:00
else
if [[ $# > 0 ]]; then
ruby $@
else
ruby *_test.rb
fi
2020-01-21 10:03:18 -05:00
fi
}
2021-11-02 20:14:26 -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";
}'
}
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
}