Ask HN: What are some small scripts you use daily?
1–10 of 59 posts
Re: Ask HN: What are some small scripts you use daily?
#2Plus all the scratch dirs are in one place so cleanup is a breeze to free up space.
Re: Ask HN: What are some small scripts you use daily?
#3I have a shell alias that creates a temp directory labeled with the current time stamp and suffixed tag then changes to it. Makes it very quick get a new scratch area for shell fu. Plus all the scratch dirs are in one place so cleanup is a breeze to free up space.
Re: Ask HN: What are some small scripts you use daily?
#4In each of those scripts, I typically have a one liner depending on what the project requires. A simple build one is:
#!/usr/bin/env bash
make build
And run: #!/usr/bin/env bash
docker run foo/bar
Or maybe: #!/usr/bin/env bash
python manage.py runserver
I might also add (source) environment variable settings, etc. Sort of like my own personal decentralized makefile.Then I add each script to my .git/info/exclude for each project. It saves so much time switching between projects to not have to remember any particular one's build or run commands.
Re: Ask HN: What are some small scripts you use daily?
#5I have a shell alias that creates a temp directory labeled with the current time stamp and suffixed tag then changes to it. Makes it very quick get a new scratch area for shell fu. Plus all the scratch dirs are in one place so cleanup is a breeze to free up space.
Sharing is caring? :)
make-scratch-dir () {
local name="$1"
local pattern='^[a-z0-9\\-]+$'
if [[ "$#" != 1 ]]; then
echo "Usage: make-scratch-dir " 1>&2
return 1
elif [[ ! "$name" =~ $pattern ]]; then
echo "Invalid name: ${name}"
fi
local full_path="$HOME/tmp/scratch/$(date +%Y%m%d-%H%M%S)-${name}"
mkdir -p "${full_path}"
pushd "${full_path}"
echo "Now in temp dir: ${full_path}"
}
The directory change is done via pushd so you can hop back via popd. Also, it restricts the suffixes to ensure the directories are all "simple" names.Re: Ask HN: What are some small scripts you use daily?
#6Re: Ask HN: What are some small scripts you use daily?
#7 web [master=] $ cat $(type -P shipit)
#!/bin/bash
exec ./shipit
web [master=] $
This allows me to tweak every projects deploy script and also maintain it in version control.Re: Ask HN: What are some small scripts you use daily?
#8Also use it a lot for syncing dotfiles in my user directory between my work and home computers.
Re: Ask HN: What are some small scripts you use daily?
#9 rebase-all ()
{
old=`git rev-parse --abbrev-ref HEAD`;
stashed=`git stash`;
for b in $(git branch --format '%(authorname) %(refname:short)' | sed -ne "s/^`git config --get user.name` //p" | grep -- -);
do
git checkout $b && git rebase origin/develop && git push --force || ( git rebase --abort && echo Could not rebase $b );
echo;
done;
git checkout $old;
if [ "$stashed" != "No local changes to save" ]; then
git stash pop;
fi
}Re: Ask HN: What are some small scripts you use daily?
#10by default it shows a list of topics. Then if you run it with the topic, it displays the details about the topic. I use it to remember how to do less frequent stuff at my day job.