TODAY_DIR="$HOME/today/"
DATE_DIR=$(date +'%Y-%m-%d')
if [ ! -d $TODAY_DIR$DATE_DIR ];
then
mkdir -p $TODAY_DIR$DATE_DIR
fi;
echo $TODAY_DIR$DATE_DIR
So you can do stuff like this with less thinking/typing: cp somefile.csv $(today)
I've been using this for a few years and continually find it handy, both at the command line and in keeping files clustered when I want to dig something up later. It is slightly less helpful if you regularly work past midnight, though!alias whitenoise='play -q -c 2 -n synth brownnoise band -n 1600 1500 tremolo .1 30'
It plays some fuzzy whitenoise, which drowns them out and lets me keep focused (music is often distracting to me).
eg: make deploy; blingle
#!/bin/bash
MSG=${@:-"Job complete"}
notify-send "$MSG"
curl -s \
--form-string "token=TOKEN" \
--form-string "user=UID" \
--form-string "message=$MSG" \
https://api.pushover.net/1/messages.jsonIn 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.
One slight modification: name the build and run scripts something that you will never expect to be in that repo (maybe like run-xyz.sh where xyz are my initials, 10 random characters, etc.).
Then, the filename can be excluded in a global gitignore file.
I'd love to have something like that as a utility
I use it all the time when I have some UNIX pipe emitting things and I want to "see" the uniques before I do sort | uniq -c type things.
#!/bin/sh awk '{ if (!h[$0]) { print $0; h[$0]=1 } }'
So, without the scrubbing:
tail -f somefile | perl -ne '!$SEEN{$_}++ and print'
Scrubbing off leading timestamps:
tail -f somefile | perl -ne 's/^[0-9:]//;!$SEEN{$_}++ and print'
push -> git push origin develop; git push origin master; git push origin --tags; terminal-notifier -title "Pushed to Git" -message "Project X"
In another directory, push may push different branches. Ditto for pull, release, keep, etc
Use them daily.
e.g.
To connect: anyconnector -c env-name
Disconnect: anyconnector -d
Get status: anyconnector -s
It gets used by my team all day, every day.Here's a copy of the script itself: https://gist.github.com/kjbweb/38508fd92669101ec1fca4bea62bc...
It works on Mac's too, so I've been told.
I use the following script to switch to dual external monitors at a standard resolution, and a counterpart script to switch back to the internal hidef monitor.
If only I could reliably fix xfce4's panel placement all of the time...and not have to restart chrome and pycharm/intelliJ on each display change!
#!/bin/bash
EXT1=`xrandr --current | sed 's/^\(.*\) connected.*$/\1/p;d' | grep -v ^eDP | head -n 1`
EXT2=`xrandr --current | sed 's/^\(.*\) connected.*$/\1/p;d' | grep HDMI | head -n 1`
INT=`xrandr --current | sed 's/^\(.*\) connected.*$/\1/p;d' | grep -v ^DP | head -n 1`
xfconf-query -c xsettings -p /Xft/DPI -s 96
xfconf-query -c xfce4-panel -p /panels/panel-1/size -s 28
xrandr \
--output VIRTUAL1 --off \
--output ${INT} --off \
--output ${EXT2} --mode 1680x1050 --pos 0x150 --rotate normal \
--output ${EXT1} --mode 1920x1200 --pos 1680x0 --rotate normal --primary cd()
{
command cd "$@"
[[ "$OLDPWD" == "$HOME"/Work/* && ! -z "$VIRTUAL_ENV" && "$OLDPWD" == *"${VIRTUAL_ENV##*/}"* && "$PWD" != *"${VIRTUAL_ENV##*/}"* ]] && deactivate
[[ -z "$VIRTUAL_ENV" && "$PWD" == "$HOME"/Work/* ]] && next="$(sed -e "s/^.*Work\///" -e "s/\/.*$//" <<< "$PWD")" && [[ -d "$WORKON_HOME"/"$next" ]] && workon "$next" && unset next
}
Yes, too many one-liners and short-circuits are usually a no-no, but it's not like anyone else is ever going to use this and I like these shortcuts.rsync -rlptvDC --progress --rsh="ssh -l username" * myserver.com
https://github.com/skx/sysadmin-util
That seems to be somewhat popular on github, but I rarely receive feedback so I'm not sure if people star because they use them too, or just because they suspect they might.
$ cat `which did`
grep $1 ~/.bash_history | sort | uniq
I also set HISTSIZE=10000000I don't mind having a large history file laying around because it's so useful.
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
}I wipe the inbox for my test gmail account every hour at the :45 minute mark using a ruby script. I don't automate the sending because it's part of the education of the prospect.
Biggest timesaver in the world for someone who listens to as much music as I do and doesn't want to deal with manually transcoding FLAC files.
iTunes and Apple Music will soon support FLAC natively, though -- previously it was out of necessity, space, and not wanting to use VLC and lose my main/single use of my Apple Watch. It's still about the latter two.
I recently also set it to output a manifest that I can feed into rsync on my work computer to pull my library from my backup server.
by 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.
I'm going to use this instead!
I have a topics hash/dictionary.
If the helpme command is run without a topic argument, it prints out all the topic keys to the dictionary one per line.
If it is run with a topic argument, it just prints out the value for that topic.
# Helper function for running command in each subdirectory under current one.
function each {
if [ -z $1 ]; then
: # If no command is given, then this is a no-op.
else
find . -maxdepth 1 -mindepth 1 -not -path '*/\.*' -type d -exec sh -c "(echo {} && cd {} && $* && echo)" \;
fi
}
zsh functions: # Helper function for navigating tmux sessions
export WORKSPACE_ROOT=$HOME/workspace
ws() {
if [ -z $1 ]; then
if [ -z $TMUX ]; then
tmux attach-session
else
cd $WORKSPACE_ROOT
fi
elif [[ $1 == 'ls' ]]; then
tmux list-sessions
else
tmux attach -t $1 || cd $WORKSPACE_ROOT/$1/src; tmux new-session -s $1
fi
}
# Helper function for running command in each subdirectory under current one.
each() {
if [ -z $1 ]; then
# If no command is given, just exit
else
find . -maxdepth 1 -mindepth 1 -not -path '*/\.*' -type d -exec sh -c "(echo {} && cd {} && $* && echo)" \;
fi
}Makes deployments blistering fast now that I've got 30 Megabit/sec up though... :)
ahk scripts:
- Easy Window Dragging (KDE style)
- Rocker (click left-right mouse button to go forward in explorer etc, right-left to go back)
- hidedesk (hides desktop icons unless I click on the desktop, sadly a bit buggy)
- some custom script to unify hotkeys for the brightness of my external dell monitor and my laptop screen.
browser fixes:
- some drag to scroll js for greasmonkey
- shortcut for bookmarking to pocket with keyboard only (with tags)
It’s transformed the office. It’s the little things ya know.
`watch-copy [copy to dir]`, which watches for changes in the current directory and builds and copies to another directory.
`set-lights [group name] [on/off/high/low]`, which posts commands to a Hue bridge.
Also use it a lot for syncing dotfiles in my user directory between my work and home computers.
The most common one I use all the time is one that changes the command prompt to show what git branch I'm on when in that directory. Just google it if you'd like.
If you repeat some command a lot or a chain of commands and it takes a lot of tedious typing, then script it.
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. #!/usr/bin/env python
import sys
def unescape(string):
print eval(string)
if __name__ == '__main__':
unescape(sys.stdin.read())Plus all the scratch dirs are in one place so cleanup is a breeze to free up space.
make-scratch-dir () {
local name="$1"
local pattern='^[a-z0-9\\-]+$'
if [[ "$#" != 1 ]]; then
echo "Usage: make-scratch-dir <name>" 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.#!/bin/bash
for i in /sites/*/.git; do ( echo $i; cd $i/..; git pull; ); done
https://myrepos.branchable.com/
For example I store all my repos beneath ~/Repos/ so I can update them all, checking out any missing ones with:
cd ~/Repos/
mr checkout
mr update #!/bin/bash
xrandr --output DVI-I-1 --brightness $1
xrandr --output HDMI-0 --brightness $1
xrandr --output DVI-D-0 --brightness $1
~