Skip to content

Instantly share code, notes, and snippets.

@esebastian
esebastian / fix-srt-names
Last active March 6, 2019 19:37
Mass rename TV show SRT files to match the MKV ones
for i in `ls *.mkv`; do [[ $i =~ [sS]([0-9]{2})[eE]([0-9]{2}) ]] && mv *${BASH_REMATCH[1]}x${BASH_REMATCH[2]}*.srt ${i%????}.srt 2> /dev/null; done
@esebastian
esebastian / find-xml
Created September 4, 2014 18:06
Find XML files, recursive
find . -print | grep -i '.*[.]xml'
@esebastian
esebastian / list-extensions
Created September 3, 2014 11:24
Print the list of different extensions from the files in a folder and its subfolders
find . -type f -name '*.*' | sed 's|.*\.||' | sort -u
@esebastian
esebastian / unsetenv
Created July 26, 2014 10:17
Unload environment variables in '.env' from the current shell session
# execute on the prompt or define it as a shell function
for i in `cat .env`; do
unset `echo $i | cut -f 1 -d "="`
done
@esebastian
esebastian / setenv
Last active August 29, 2015 14:04
Load environment variables from '.env' into the current shell session
# execute on the prompt or define it as a shell function
for i in `cat .env`; do
export $i
done
@esebastian
esebastian / git-subdir
Created July 5, 2014 18:18
Move the current git working tree into a subfolder
#!/bin/sh
# Move the current working tree into a subfolder.
#
# This will rewite all branches and tags, so this should not
# be performed on a repo that has been shared with others, because it
# will force them to reset their history.
#
# Use at your own risk.
#
# Put the script in your path and invoke it this way:
@esebastian
esebastian / git-fix-dates
Created July 5, 2014 18:15
Reset the commit dates to their corresponding author dates
#!/bin/sh
# Reset the commit dates to their corresponding author dates, in the current
# branch. Usually useful to preserve the original timestamps after a rebase.
#
# This action is destructive to your repo's history and this should not
# be performed on a repo that has been shared with others, because it
# will force them to reset their history.
#
# Use at your own risk.
#
@esebastian
esebastian / git-unvoid-messages
Created July 5, 2014 18:08
Apply messages from provided input file to git commits with empty messages
#!/bin/sh
# Apply messages from provided input file to commits with empty messages
# The messages are applied in inverse order (first line in the file applied to older commit with void message)
# and only up to the number of commits with empty messages.
#
# This action is destructive to your repo's history. It's best to do this on a clone,
# just in case. Also beware that this should not be performed on a repo that has been
# shared with others without forcing them to reset their history.
#
# Use at your own risk.
@esebastian
esebastian / git-author
Created July 5, 2014 18:04
Rewrite git history replacing both author and commiter data for a given matching email
#!/bin/sh
# Git script to rewrite history replacing both author and commiter data for a given matching email,
# based upon this nice gist: https://help.github.com/articles/changing-author-info
# As the original source states, this action is destructive to your repo's history.
# It's best to do this on a clone, just in case. Also beware that this should not be performed on
# a repo that has been shared with others without forcing them to reset their history.
#
# Use at your own risk.
#
@esebastian
esebastian / git-amend
Last active May 18, 2022 13:14
Amend the commit message of one specific git commit and rebase to apply the changes
#!/bin/sh
# Amend the commit message one specific commit and rebase
# to apply the changes. Given the SHA hash or a reference
# of the commit to amend, it checkouts the commit, amends
# it interactively and rebases the repo history in master.
#
# This action is destructive to your repo's history and this
# should not be performed on a repo that has been shared with
# others, because it will force them to reset their history.
#