Created
December 13, 2015 23:55
-
-
Save adamheins/d508e2953f26701a897c to your computer and use it in GitHub Desktop.
Simple command line note taking script.
This file contains 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
#!/bin/zsh | |
# Author: Adam Heins | |
# Date: 2015-10-22 | |
t() { | |
# Make the ~/.t directory if it does not exist. | |
[ ! -d ~/.t ] && mkdir ~/.t | |
if [ -z "$1" ]; then | |
local last cur_dir | |
[ -f ~/.tlast ] && last=$(head -n 1 ~/.tlast) | |
# Save current directory to return to later. | |
cur_dir=$(pwd) | |
cd ~/.t | |
"$EDITOR" $last | |
cd $cur_dir | |
return | |
fi | |
case "$1" in | |
"--") | |
"$EDITOR" ~/.t/"$2" | |
;; | |
"-h"|"--help") | |
echo -e "usage: t [-h] [-l] [-r FILE]\n" | |
echo -e "arguments:" | |
echo -e " -h, --help show this help message" | |
echo -e " -l, --list list all files in ~/.t" | |
echo -e " -r, --remove FILE remove a file from ~/.t" | |
;; | |
"-l"|"--list") | |
ls ~/.t | |
;; | |
"-r"|"--remove") | |
# Bail if the user tries to delete something outside this directory. | |
[[ "${2:0:2}" == ".." ]] && return 1; | |
rm ~/.t/"$2" | |
;; | |
*) | |
"$EDITOR" ~/.t/"$1" | |
# If the file existed (it has been saved), copy it into the last file | |
# store. | |
[ -f ~/.t/"$1" ] && echo "$1" > ~/.tlast | |
;; | |
esac | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment