Last active
August 29, 2015 13:57
-
-
Save rickcnagy/9627714 to your computer and use it in GitHub Desktop.
Create incremental file from input text (for Alfred Workflow)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd ~/Desktop | |
# incremental filename | |
# http://stackoverflow.com/a/806923/1628796 | |
isnumeric() { | |
re='^[0-9]+$' | |
if ! [[ $1 =~ $re ]] ; then | |
echo 0 | |
else | |
echo 1 | |
fi | |
} | |
biggestNum=0 | |
for f in ls text_*.txt; do | |
filename="${f%.*}" | |
filenum=${filename:5:10} | |
if [[ $(isnumeric "$filenum") == 1 ]] ; then | |
if [[ $biggestNum -lt $filenum ]] ; then | |
biggestNum=$filenum | |
fi | |
fi | |
done | |
# create and open file | |
newFilename="text_$(($biggestNum + 1)).txt" | |
touch $newFilename | |
echo "{query}" >> "$newFilename" | |
open $newFilename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment