Skip to content

Instantly share code, notes, and snippets.

@rickcnagy
Last active August 29, 2015 13:57
Show Gist options
  • Save rickcnagy/9627714 to your computer and use it in GitHub Desktop.
Save rickcnagy/9627714 to your computer and use it in GitHub Desktop.
Create incremental file from input text (for Alfred Workflow)
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