Last active
March 15, 2023 13:07
-
-
Save MarcelFox/0236adec544a00396fe3902c803c9c24 to your computer and use it in GitHub Desktop.
bash function for agenda
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
function agenda() { | |
DIR_PATH="$HOME/.agenda" | |
if [ ! -d $DIR_PATH ]; then | |
mkdir $DIR_PATH | |
fi | |
if [ -z "$1" ] | |
then | |
if [ ! -f "$DIR_PATH/agenda.txt" ]; | |
then | |
printf "File $DIR_PATH does not exists, create it? (y/n): "; | |
read var_decision; | |
if [[ $var_decision == "y" ]] || [[ $var_decision == "Y" ]]; | |
then | |
touch "$DIR_PATH/agenda.txt" | |
elif [[ $var_decision == "n" ]] || [[ $var_decision == "N" ]]; | |
then | |
printf "Ok, nothing done!\n"; | |
else | |
printf "\n${BOLD}Please inform only 'y' or 'n'. Closing...${NO_STL}\n\n"; | |
fi; | |
else | |
less +G $DIR_PATH/agenda.txt | |
fi | |
elif [ -n "$1" ] | |
then | |
var="$1" | |
case "$var" in | |
"-e"|"--edit") | |
if [ -z "$2" ] | |
then | |
emacs $DIR_PATH/agenda.txt --eval "(with-current-buffer \"agenda.txt\" (insert-current-date))" | |
elif [ -n "$2" ] | |
then | |
emacs $DIR_PATH/$2 --eval "(with-current-buffer \"$2\" (insert-current-date))" | |
fi | |
;; | |
"-n"|"--new") | |
if [ -z "$2" ] | |
then | |
echo "Please inform a file name (example: file.txt)" | |
elif [ -n "$2" ] | |
then | |
emacs $DIR_PATH/$2 --eval "(with-current-buffer \"$2\" (insert-current-date))" | |
fi | |
;; | |
"-r"|"--read") | |
if [ -z "$2" ] | |
then | |
echo "Please inform a file name (example: file.txt)" | |
elif [ -n "$2" ] | |
then | |
less +G $DIR_PATH/$2 | |
if [[ $? -eq 1 ]] | |
then | |
printf "\nFile '$2' was not found.\n\n" | |
fi | |
fi | |
;; | |
"-l"|"--list") | |
ls $HOME/.agenda/ | awk "/txt/ && !/~/ && !/#/" | |
;; | |
"-h"|"--help") | |
echo "AGENDA:" | |
echo | |
echo "usage: agenda [args] [file ..]" | |
echo | |
echo "Args:" | |
echo " -e | --edit [FILE] Edit/Create a file with emacs. If no file is provided, edits agenda.txt" | |
echo " -n | --new [FILE] Creates a new file for edition with emacs" | |
echo " -r | --read Opens a new file to be read with 'less'" | |
echo " -l | --list Lists the available text files under $DIR_PATH" | |
echo " -h | --help Show this menu" | |
;; | |
*) | |
echo "Unknown Argument. Try '--help'" | |
;; | |
esac | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dependencies:
Emacs configuration:
You must add the following configuration under your .emacs:
Emacs config
Installation:
export -f agenda
$ source ~/.bashrc
Usage: