Compare commits
2 Commits
83928f3cec
...
c506348422
| Author | SHA1 | Date | |
|---|---|---|---|
| c506348422 | |||
| 85464f66b3 |
@@ -1,30 +1,82 @@
|
|||||||
# Shell Functions
|
# Shell Functions
|
||||||
|
|
||||||
# Shell note pad
|
# Shell note pad for Bash
|
||||||
note () {
|
noteb () {
|
||||||
# if file doesn't exist, create it
|
local notes_file="$HOME/.notes"
|
||||||
if [[ ! -f $HOME/.notes ]]; then
|
local timestamp=$(date +"%F %T")
|
||||||
touch "$HOME/.notes"
|
local input_line
|
||||||
fi
|
|
||||||
|
|
||||||
if ! (($#)); then
|
if [[ $# -eq 0 ]]; then
|
||||||
# no arguments, print file
|
# No arguments, display the notes file
|
||||||
cat "$HOME/.notes"
|
tac "$notes_file"
|
||||||
|
return 0
|
||||||
|
elif [[ "$1" == "-a" ]]; then
|
||||||
|
# Add a note with prompting (using Bash's read -p)
|
||||||
|
read -r -p "$(date +"%F %T | ") " input_line
|
||||||
|
if [[ -n "$input_line" ]]; then
|
||||||
|
echo "$timestamp | $input_line" >> "$notes_file"
|
||||||
|
echo "Note added to $notes_file"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "No note entered."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
elif [[ "$1" == "-c" ]]; then
|
elif [[ "$1" == "-c" ]]; then
|
||||||
# clear file
|
# Clear the notes file
|
||||||
echo -n "Clear notes file? [Y/N] "
|
read -r -p "Clear notes file? [Y/n] " clear_response
|
||||||
read replace
|
if [[ "$clear_response" =~ ^[Yy]$ ]]; then
|
||||||
if [ "${replace}" = "Y" ] || [ "${replace}" = "y" ]; then
|
> "$notes_file" # Truncate the file
|
||||||
echo "Emptying notes file..."
|
echo "Notes file cleared."
|
||||||
printf "%s" > "$HOME/.notes"
|
else
|
||||||
echo "Done."
|
echo "Notes file not cleared."
|
||||||
else
|
fi
|
||||||
echo "Notes file preserved."
|
return 0
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
# add all arguments to file
|
# Treat arguments as the note (default action if not -a or -c)
|
||||||
echo -n $(date +"%F %T | ") >> "$HOME/.notes"
|
input_line="$*"
|
||||||
printf "%s\n" "$*" >> "$HOME/.notes"
|
echo "$timestamp | $input_line" >> "$notes_file"
|
||||||
|
echo "Note added to $notes_file"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Shell Note Pad for ZSH
|
||||||
|
notez () {
|
||||||
|
local notes_file="$HOME/.notes"
|
||||||
|
local timestamp=$(date +"%F %T")
|
||||||
|
local input_line
|
||||||
|
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
# No arguments, display the notes file
|
||||||
|
cat "$notes_file"
|
||||||
|
return 0
|
||||||
|
elif [[ "$1" == "-a" ]]; then
|
||||||
|
# Add a note with prompting
|
||||||
|
read -r "?$(date +"%F %T | ") " input_line
|
||||||
|
if [[ -n "$input_line" ]]; then
|
||||||
|
echo "$timestamp | $input_line" >> "$notes_file"
|
||||||
|
echo "Note added to $notes_file"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
echo "No note entered."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
elif [[ "$1" == "-c" ]]; then
|
||||||
|
# Clear the notes file
|
||||||
|
read -r "?Clear notes file? [Y/n] " clear_response
|
||||||
|
if [[ "$clear_response" =~ ^[Yy]$ ]]; then
|
||||||
|
> "$notes_file" # Truncate the file
|
||||||
|
echo "Notes file cleared."
|
||||||
|
else
|
||||||
|
echo "Notes file not cleared."
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
# Treat arguments as the note (default action if not -a or -c)
|
||||||
|
input_line="$*"
|
||||||
|
echo "$timestamp | $input_line" >> "$notes_file"
|
||||||
|
echo "Note added to $notes_file"
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user