feat: add an optional fun animation on the bottom

This commit is contained in:
Joey Huang 2025-06-16 16:22:26 +08:00
commit df6b695dd6
8 changed files with 1545 additions and 777 deletions

View file

@ -4,15 +4,17 @@
# A powerful sidebar-style task manager that runs entirely in your terminal
#
# Author: @oiahoon
# Version: 1.0.0
# Version: 2.0.0
# Repository: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/taskman
#
# Features:
# - Interactive terminal UI with keyboard shortcuts
# - Command line interface for quick operations
# - Priority system with color coding
# - Persistent JSON storage
# - Persistent JSON storage with configurable location
# - Vim-like keybindings
# - Multiple sorting modes with completed tasks at bottom
# - Color-coded bullets with neutral task text
# - Zero external dependencies (Python 3 only)
#
@ -22,8 +24,21 @@ TASKMAN_PLUGIN_DIR="${0:h}"
# Data directory (store tasks in home directory)
TASKMAN_DATA_DIR="$HOME/.taskman"
# Ensure data directory exists
[[ ! -d "$TASKMAN_DATA_DIR" ]] && mkdir -p "$TASKMAN_DATA_DIR"
# Allow users to configure custom task file path
# Users can set TASKMAN_DATA_FILE in their .zshrc to customize storage location
# Example: export TASKMAN_DATA_FILE="$HOME/my-tasks/tasks.json"
if [[ -z "$TASKMAN_DATA_FILE" ]]; then
TASKMAN_DATA_FILE="$TASKMAN_DATA_DIR/tasks.json"
fi
# Ensure data directory exists (for default path)
if [[ "$TASKMAN_DATA_FILE" == "$TASKMAN_DATA_DIR/tasks.json" ]]; then
[[ ! -d "$TASKMAN_DATA_DIR" ]] && mkdir -p "$TASKMAN_DATA_DIR"
else
# For custom paths, ensure the directory exists
custom_dir=$(dirname "$TASKMAN_DATA_FILE")
[[ ! -d "$custom_dir" ]] && mkdir -p "$custom_dir"
fi
# Color definitions for output
TASKMAN_COLOR_RED="\033[31m"
@ -36,8 +51,12 @@ TASKMAN_COLOR_RESET="\033[0m"
# Main task manager function
tasks() {
local action="$1"
shift
# Only shift if there are arguments
if [[ $# -gt 0 ]]; then
shift
fi
case "$action" in
"" | "ui" | "show")
# Launch the full UI
@ -59,6 +78,10 @@ tasks() {
# Delete a task
_taskman_delete_task "$@"
;;
"sort")
# Set sorting mode
_taskman_set_sort "$@"
;;
"help" | "-h" | "--help")
_taskman_show_help
;;
@ -77,12 +100,12 @@ _taskman_launch_ui() {
echo "${TASKMAN_COLOR_YELLOW}Please install Python 3 to use the interactive UI.${TASKMAN_COLOR_RESET}"
return 1
fi
# Set the data file path
export TASKMAN_DATA_FILE="$TASKMAN_DATA_DIR/tasks.json"
# Set the data file path (use configured path)
export TASKMAN_DATA_FILE
# Run the Python task manager
python3 "$TASKMAN_PLUGIN_DIR/bin/task_manager.py"
python3 "$TASKMAN_PLUGIN_DIR/task_manager.py"
}
# Quick add task from command line
@ -92,10 +115,10 @@ _taskman_add_task() {
echo "Usage: tasks add <task description> [priority]"
return 1
fi
local task_text="$1"
local priority="${2:-normal}"
# Validate priority
case "$priority" in
"high"|"normal"|"low")
@ -105,10 +128,10 @@ _taskman_add_task() {
priority="normal"
;;
esac
if command -v python3 >/dev/null 2>&1; then
python3 "$TASKMAN_PLUGIN_DIR/bin/task_cli.py" add "$task_text" "$priority"
TASKMAN_DATA_FILE="$TASKMAN_DATA_FILE" python3 "$TASKMAN_PLUGIN_DIR/task_cli.py" add "$task_text" "$priority"
# Show color-coded confirmation
local priority_color
case "$priority" in
@ -116,7 +139,7 @@ _taskman_add_task() {
"low") priority_color="$TASKMAN_COLOR_CYAN" ;;
*) priority_color="$TASKMAN_COLOR_YELLOW" ;;
esac
echo "${TASKMAN_COLOR_GREEN}✓ Added task:${TASKMAN_COLOR_RESET} ${priority_color}[$priority]${TASKMAN_COLOR_RESET} $task_text"
else
echo "${TASKMAN_COLOR_RED}Error: Python 3 is required for task management.${TASKMAN_COLOR_RESET}"
@ -127,9 +150,9 @@ _taskman_add_task() {
# List tasks in terminal
_taskman_list_tasks() {
local filter="$1"
if command -v python3 >/dev/null 2>&1; then
python3 "$TASKMAN_PLUGIN_DIR/bin/task_cli.py" list "$filter"
TASKMAN_DATA_FILE="$TASKMAN_DATA_FILE" python3 "$TASKMAN_PLUGIN_DIR/task_cli.py" list "$filter"
else
echo "${TASKMAN_COLOR_RED}Error: Python 3 is required for task management.${TASKMAN_COLOR_RESET}"
return 1
@ -143,10 +166,10 @@ _taskman_complete_task() {
echo "Usage: tasks done <task_id>"
return 1
fi
local task_id="$1"
if command -v python3 >/dev/null 2>&1; then
python3 "$TASKMAN_PLUGIN_DIR/bin/task_cli.py" complete "$task_id"
TASKMAN_DATA_FILE="$TASKMAN_DATA_FILE" python3 "$TASKMAN_PLUGIN_DIR/task_cli.py" complete "$task_id"
else
echo "${TASKMAN_COLOR_RED}Error: Python 3 is required for task management.${TASKMAN_COLOR_RESET}"
return 1
@ -160,10 +183,28 @@ _taskman_delete_task() {
echo "Usage: tasks delete <task_id>"
return 1
fi
local task_id="$1"
if command -v python3 >/dev/null 2>&1; then
python3 "$TASKMAN_PLUGIN_DIR/bin/task_cli.py" delete "$task_id"
TASKMAN_DATA_FILE="$TASKMAN_DATA_FILE" python3 "$TASKMAN_PLUGIN_DIR/task_cli.py" delete "$task_id"
else
echo "${TASKMAN_COLOR_RED}Error: Python 3 is required for task management.${TASKMAN_COLOR_RESET}"
return 1
fi
}
# Set sorting mode
_taskman_set_sort() {
if [[ $# -eq 0 ]]; then
echo "${TASKMAN_COLOR_RED}Error: Please provide sort mode${TASKMAN_COLOR_RESET}"
echo "Usage: tasks sort <mode>"
echo "Available modes: default, priority, alphabetical"
return 1
fi
local sort_mode="$1"
if command -v python3 >/dev/null 2>&1; then
TASKMAN_DATA_FILE="$TASKMAN_DATA_FILE" python3 "$TASKMAN_PLUGIN_DIR/task_cli.py" sort "$sort_mode"
else
echo "${TASKMAN_COLOR_RED}Error: Python 3 is required for task management.${TASKMAN_COLOR_RESET}"
return 1
@ -173,7 +214,7 @@ _taskman_delete_task() {
# Show help
_taskman_show_help() {
cat << 'EOF'
Terminal Task Manager - Oh-My-Zsh Plugin
Terminal Task Manager - Oh-My-Zsh Plugin v2.0
Usage:
tasks [action] [arguments]
@ -185,6 +226,7 @@ Actions:
list [filter] List tasks (filter: all, pending, completed)
done <id> Mark task as completed
delete <id> Delete a task
sort <mode> Set sorting mode (default, priority, alphabetical)
help Show this help
Examples:
@ -195,45 +237,95 @@ Examples:
tasks list pending # List only pending tasks
tasks done 3 # Mark task ID 3 as completed
tasks delete 5 # Delete task ID 5
tasks sort priority # Sort by priority
Interactive UI Keys:
↑/k Move up n New task
↓/j Move down Space Toggle completion
h Help d Delete task
q Quit
s Cycle sort d Delete task
p Sort priority a Sort alphabetical
h Help q Quit
Aliases:
tm, task, todo - All point to 'tasks' command
Features:
• Configurable storage location via TASKMAN_DATA_FILE environment variable
• Automatic sorting with completed tasks always at bottom
• Priority-based text colors with dimmed completed tasks
• Humanized creation timers showing task age
• Visual separator between active and completed tasks
• Multiple sort modes: creation order, priority, alphabetical
Priority Colors:
• High Priority (!) - Red text for active, dimmed red for completed
• Normal Priority (-) - Yellow text for active, dimmed yellow for completed
• Low Priority (·) - Cyan text for active, dimmed cyan for completed
Data Storage:
Tasks are stored in: ~/.taskman/tasks.json
Default: ~/.taskman/tasks.json
Custom: Set TASKMAN_DATA_FILE environment variable
Requirements:
Python 3.6+ (for interactive UI and CLI operations)
Configuration:
# In your ~/.zshrc (before loading Oh-My-Zsh)
export TASKMAN_DATA_FILE="$HOME/Documents/my-tasks.json"
Priority Levels:
• High Priority (!) - Red text, for urgent tasks
• Normal Priority (-) - Yellow text, default priority
• Low Priority (·) - Cyan text, for less urgent tasks
Color Scheme:
• Task text is colored based on priority and completion status
• Completed tasks show dimmed priority colors to maintain context
• Visual separator divides active and completed tasks
EOF
}
# Convenient aliases
# Aliases for convenience
alias taskman='tasks'
alias tm='tasks'
alias task='tasks'
alias todo='tasks'
# Auto-completion for task actions
_taskman_completion() {
local -a actions
actions=(
'ui:Launch interactive UI'
'show:Launch interactive UI'
'add:Add new task'
'new:Add new task'
'create:Add new task'
'list:List tasks'
'ls:List tasks'
'done:Mark task complete'
'complete:Mark task complete'
'delete:Delete task'
'del:Delete task'
'rm:Delete task'
'sort:Set sorting mode'
'help:Show help'
)
_describe 'actions' actions
}
compdef _taskman_completion tasks tm task todo
# Quick access function for sidebar workflow
task-sidebar() {
echo "${TASKMAN_COLOR_BLUE}Starting task manager in sidebar mode...${TASKMAN_COLOR_RESET}"
echo "${TASKMAN_COLOR_YELLOW}Tip: Use terminal split to run this alongside your work${TASKMAN_COLOR_RESET}"
echo "${TASKMAN_COLOR_YELLOW}Tip: Use 'Cmd+D' (or equivalent) to split terminal horizontally${TASKMAN_COLOR_RESET}"
echo "${TASKMAN_COLOR_CYAN}New features: Sort with 's/p/a' keys, completed tasks auto-move to bottom${TASKMAN_COLOR_RESET}"
tasks ui
}
# Optional: Show task summary on shell startup
# Uncomment the next line to enable startup summary
# Show a quick summary on shell startup (optional)
# Uncomment the next line if you want to see task summary when opening terminal
# _taskman_startup_summary
_taskman_startup_summary() {
if [[ -f "$TASKMAN_DATA_DIR/tasks.json" ]] && command -v python3 >/dev/null 2>&1; then
local pending_count=$(python3 "$TASKMAN_PLUGIN_DIR/bin/task_cli.py" count pending 2>/dev/null || echo "0")
local completed_count=$(python3 "$TASKMAN_PLUGIN_DIR/bin/task_cli.py" count completed 2>/dev/null || echo "0")
if [[ -f "$TASKMAN_DATA_FILE" ]] && command -v python3 >/dev/null 2>&1; then
local pending_count=$(TASKMAN_DATA_FILE="$TASKMAN_DATA_FILE" python3 "$TASKMAN_PLUGIN_DIR/task_cli.py" count pending 2>/dev/null || echo "0")
local completed_count=$(TASKMAN_DATA_FILE="$TASKMAN_DATA_FILE" python3 "$TASKMAN_PLUGIN_DIR/task_cli.py" count completed 2>/dev/null || echo "0")
if [[ "$pending_count" -gt 0 ]]; then
echo "${TASKMAN_COLOR_CYAN}📋 Task Summary: ${pending_count} pending, ${completed_count} completed${TASKMAN_COLOR_RESET}"
echo "${TASKMAN_COLOR_YELLOW} Type 'tasks' to manage your tasks${TASKMAN_COLOR_RESET}"