Todo Bash
Build |
Status |
---|---|
A Linux (command line) ‘TODO’ AppImage, function, and script.
Index
Disclaimer
I wrote this as a temporary option until I write my Fortran
version. This still works great as is if you prefer a script.
Usage
Use the script and AppImage in the exact same way.
@Usage: todo [INDEX]...
todo [OPTIONS [INDEX|ITEM]...]...
List, add, or remove todo items.
@OPTIONS:
-h,--help This help message.
-r,--remove Remove an item by INDEX number.
-a,--add Add an item by ITEM.
-q,--quiet No error messages.
@INDEX:
Integers Index number of item.
@ITEM:
String Todo ITEM.
@EXAMPLES:
todo
List all items in todo list.
todo 1
List 1st ITEM in todo list.
todo -a "Something to do"
Add a todo item.
todo -r 1
Remove item at index #1.
Installation
Install the script and AppImage in the exact same way.
- Download the script file: [todo] or get it from the official release page:
- How to use:
- Place the script anywhere in your $PATH directories and/or…
- Execute/Run or Source the file:
- Run like any other script/file:
$ /path/to/todo --help $ # or in directory: $ ./todo -a "Do this thing" $ # or if in $PATH $ todo -r 1
- Or source the file with Completion:
$ . /path/to/todo $ # or $ source /path/to/todo $ # or if in $PATH or directory: $ . todo
- Run like any other script/file:
- Change the file permissions to be executable:
chmod u+x /path/to/script/file # for you only
# or
chmod +x /path/to/script/file # for any user
- If you only use the fucntion you can copy & paste the following line (also found in the script) without the comment ‘#’ to any of your script/config/.dotfiles to enable Bash Completion:
complete -W '-h --help -r --remove -a --add -q --quiet' todo
Installation - Alternate
-
Copy & paste the function from the script file to your own function/script/config file.
-
Repeat the same process as above for Bash Completion.
Screenshots
Function & Bash Completion
#!/usr/bin/env bash
# This file can be sourced or executed.
# More information below at the "Execution" section
# Todo Function
function todo(){
local conf="${HOME}/.config/.todo"
local iterVal mode array
[[ -f "${conf}" ]] ||
cat /dev/null > "${conf}"
sed -i '/^\s*$/d' "${conf}"
sed -i '/^$/d' "${conf}"
case "$1" in
-h|--help) mode=0 ;;
-r|--remove) mode=1 ;;
-a|--add) mode=2 ;;
*[0-9]*) mode=3 ;;
-q|--quiet) mode=4 ;;
*) mode=5 ;;
esac
if [[ "${mode}" =~ ^[0-5]$ ]]; then
if [[ "${mode}" -eq 0 ]]; then
cat << EOF
@Usage: todo [INDEX]...
todo [OPTIONS [INDEX|ITEM]...]...
List, add, or remove todo items.
@OPTIONS:
-h,--help This help message.
-r,--remove Remove an item by INDEX number.
-a,--add Add an item by ITEM.
-q,--quiet No error messages.
@INDEX:
Integers Index number of item.
@ITEM:
String Todo ITEM.
@EXAMPLES:
todo
List all items in todo list.
todo 1
List 1st ITEM in todo list.
todo -a "Something to do"
Add a todo item.
todo -r 1
Remove item at index #1.
EOF
elif [[ "${mode}" -eq 1 ]]; then
sed -i -e "${2}d" "${conf}"
return
elif [[ "${mode}" -eq 2 ]]; then
echo "$2" >> "${conf}"
return
elif [[ "${mode}" -eq 3 ]]; then
readarray -t array < "${conf}"
echo "${array[$((${1} - 1))]}"
return
else
readarray -t array < "${conf}"
if [[ ${#array[@]} -eq 0 ]]; then
[[ ${mode} -ne 4 ]] &&
echo "No items in the TODO list."
return
fi
for iterVal in "${!array[@]}"; do
echo "[$((${iterVal} + 1))]:${array[${iterVal}]}"
done
return
fi
fi
}
# Test if this file is being sourced or executed.
$(return >/dev/null 2>&1)
# If file is sourced the enable Bash Completion
if [ "$?" -eq "0" ]; then
complete -W '-h --help -r --remove -a --add -q --quiet' todo
else
# If not sourced the run the function with possible params.
todo "$@"
fi
File Links
File | Description |
---|---|
Bash Script | Script File |
AppImage | Compiled AppImage. |
Project Links
Link | Description |
---|---|
Official Project Page | The themed version of this page. |
Project Page | This repository page. |
Current Releases | The release files in “Continuous Build”. |
License
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.