feat(plugins): Added the official bootstrap plugin repository
This commit is contained in:
74
plugins/sysinfo.sh
Normal file
74
plugins/sysinfo.sh
Normal file
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
# System Information Dashboard Plugin for bootstrap CLI
|
||||
|
||||
main() {
|
||||
if [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ]; then
|
||||
echo "Usage: b sysinfo"
|
||||
echo ""
|
||||
echo "Displays a beautiful system resource and hardware information dashboard."
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
echo -e " ${GREEN}SYSTEM INFORMATION DASHBOARD${NC}"
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
|
||||
# OS Info
|
||||
local os_name="Unknown"
|
||||
if [ -f /etc/os-release ]; then
|
||||
os_name=$(grep "^PRETTY_NAME=" /etc/os-release | cut -d= -f2 | tr -d '"')
|
||||
elif [ "$(uname)" = "Darwin" ]; then
|
||||
os_name="macOS $(sw_vers -productVersion)"
|
||||
else
|
||||
os_name=$(uname -s)
|
||||
fi
|
||||
echo -e "${BLUE}OS:${NC} $os_name"
|
||||
echo -e "${BLUE}Kernel:${NC} $(uname -r)"
|
||||
echo -e "${BLUE}Uptime:${NC} $(uptime | sed 's/^ *//')"
|
||||
|
||||
# CPU Info
|
||||
local cpu_info="Unknown"
|
||||
if [ -f /proc/cpuinfo ]; then
|
||||
cpu_info=$(grep -m1 "model name" /proc/cpuinfo | cut -d: -f2 | sed 's/^ *//')
|
||||
elif [ "$(uname)" = "Darwin" ]; then
|
||||
cpu_info=$(sysctl -n machdep.cpu.brand_string)
|
||||
fi
|
||||
echo -e "${BLUE}CPU:${NC} $cpu_info"
|
||||
|
||||
# Load Average
|
||||
local load_avg
|
||||
load_avg=$(uptime | awk -F'load average:' '{ print $2 }' | sed 's/^ *//')
|
||||
echo -e "${BLUE}Load Avg:${NC} $load_avg"
|
||||
|
||||
# Memory Usage
|
||||
echo -e "${BLUE}Memory:${NC}"
|
||||
if has_command free; then
|
||||
free -h | awk 'NR==2{printf " Used: %s / Total: %s (%.2f%%)\n", $3, $2, $3/$2*100}'
|
||||
elif [ -f /proc/meminfo ]; then
|
||||
local mem_total
|
||||
mem_total=$(grep "MemTotal" /proc/meminfo | awk '{print $2}')
|
||||
local mem_free
|
||||
mem_free=$(grep "MemFree" /proc/meminfo | awk '{print $2}')
|
||||
local mem_used=$((mem_total - mem_free))
|
||||
# Convert to MB
|
||||
local total_mb=$((mem_total / 1024))
|
||||
local used_mb=$((mem_used / 1024))
|
||||
local pct=$((used_mb * 100 / total_mb))
|
||||
echo " Used: ${used_mb}MB / Total: ${total_mb}MB (${pct}%)"
|
||||
elif [ "$(uname)" = "Darwin" ]; then
|
||||
local total_mem
|
||||
total_mem=$(sysctl -n hw.memsize)
|
||||
local total_gb=$((total_mem / 1024 / 1024 / 1024))
|
||||
echo " Total: ${total_gb}GB"
|
||||
else
|
||||
echo " Unavailable"
|
||||
fi
|
||||
|
||||
# Disk Usage
|
||||
echo -e "${BLUE}Disk Space (Root):${NC}"
|
||||
df -h / | awk 'NR==2{printf " Used: %s / Total: %s (%s)\n", $3, $2, $5}'
|
||||
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
123
plugins/todo.sh
Normal file
123
plugins/todo.sh
Normal file
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env bash
|
||||
# Todo List Plugin for bootstrap CLI
|
||||
|
||||
TODO_FILE="$HOME/.local/share/bootstrap/todo.txt"
|
||||
|
||||
main() {
|
||||
mkdir -p "$(dirname "$TODO_FILE")"
|
||||
[ ! -f "$TODO_FILE" ] && touch "$TODO_FILE"
|
||||
|
||||
local action="${1:-list}"
|
||||
case "$action" in
|
||||
add)
|
||||
shift
|
||||
if [ -z "$*" ]; then
|
||||
log_error "Please specify a task to add."
|
||||
echo "Usage: b todo add <task description>"
|
||||
return 1
|
||||
fi
|
||||
echo "[ ] $*" >> "$TODO_FILE"
|
||||
log_success "Added task: $*"
|
||||
;;
|
||||
list)
|
||||
if [ ! -s "$TODO_FILE" ]; then
|
||||
log_info "Your todo list is empty. Add a task with: b todo add <task>"
|
||||
return 0
|
||||
fi
|
||||
echo -e "${BLUE}--- YOUR TODO LIST ---${NC}"
|
||||
local line_num=1
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
# Highlight completed tasks
|
||||
if [[ "$line" == "[\x]"* || "$line" == "[x]"* ]]; then
|
||||
echo -e " ${line_num}. ${GREEN}${line}${NC}"
|
||||
else
|
||||
echo -e " ${line_num}. ${line}"
|
||||
fi
|
||||
line_num=$((line_num + 1))
|
||||
done < "$TODO_FILE"
|
||||
;;
|
||||
done)
|
||||
shift
|
||||
local task_num="${1:-}"
|
||||
if [[ ! "$task_num" =~ ^[0-9]+$ ]]; then
|
||||
log_error "Please specify a valid task number."
|
||||
echo "Usage: b todo done <number>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local total_tasks
|
||||
total_tasks=$(wc -l < "$TODO_FILE")
|
||||
if [ "$task_num" -lt 1 ] || [ "$task_num" -gt "$total_tasks" ]; then
|
||||
log_error "Task number out of range (1-$total_tasks)."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Update the task at line task_num to be marked [x]
|
||||
local temp_file
|
||||
temp_file=$(mktemp)
|
||||
local line_num=1
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
if [ "$line_num" -eq "$task_num" ]; then
|
||||
# Replace [ ] with [x]
|
||||
echo "${line/\[ \]/\[x\]}" >> "$temp_file"
|
||||
else
|
||||
echo "$line" >> "$temp_file"
|
||||
fi
|
||||
line_num=$((line_num + 1))
|
||||
done < "$TODO_FILE"
|
||||
mv "$temp_file" "$TODO_FILE"
|
||||
log_success "Marked task #$task_num as completed."
|
||||
;;
|
||||
rm|remove)
|
||||
shift
|
||||
local task_num="${1:-}"
|
||||
if [[ ! "$task_num" =~ ^[0-9]+$ ]]; then
|
||||
log_error "Please specify a valid task number to remove."
|
||||
echo "Usage: b todo rm <number>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local total_tasks
|
||||
total_tasks=$(wc -l < "$TODO_FILE")
|
||||
if [ "$task_num" -lt 1 ] || [ "$task_num" -gt "$total_tasks" ]; then
|
||||
log_error "Task number out of range (1-$total_tasks)."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Remove the line at task_num
|
||||
local temp_file
|
||||
temp_file=$(mktemp)
|
||||
local line_num=1
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
if [ "$line_num" -ne "$task_num" ]; then
|
||||
echo "$line" >> "$temp_file"
|
||||
fi
|
||||
line_num=$((line_num + 1))
|
||||
done < "$TODO_FILE"
|
||||
mv "$temp_file" "$TODO_FILE"
|
||||
log_success "Removed task #$task_num."
|
||||
;;
|
||||
clear)
|
||||
> "$TODO_FILE"
|
||||
log_success "Cleared all tasks from your todo list."
|
||||
;;
|
||||
--help|-h)
|
||||
echo "Usage: b todo [action] [args]"
|
||||
echo ""
|
||||
echo "Actions:"
|
||||
echo " list Show all tasks (default)"
|
||||
echo " add <task> Add a new task"
|
||||
echo " done <number> Mark a task as completed"
|
||||
echo " rm <number> Remove a task"
|
||||
echo " clear Delete all tasks"
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown action: $action"
|
||||
echo "Run 'b todo --help' for usage instructions."
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
32
plugins/weather.sh
Normal file
32
plugins/weather.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# Weather Plugin for bootstrap CLI
|
||||
|
||||
main() {
|
||||
if [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ]; then
|
||||
echo "Usage: b weather [location]"
|
||||
echo ""
|
||||
echo "Fetches and displays a neat weather forecast."
|
||||
echo "If no location is specified, it auto-detects based on your IP."
|
||||
return 0
|
||||
fi
|
||||
|
||||
local location="$*"
|
||||
log_info "Fetching weather forecast..."
|
||||
|
||||
if [ -n "$location" ]; then
|
||||
# URL encode the location (replace spaces with +)
|
||||
local encoded_location
|
||||
encoded_location=$(echo "$location" | tr ' ' '+')
|
||||
if ! curl -sS "wttr.in/${encoded_location}?0&m"; then
|
||||
log_error "Failed to fetch weather for '$location'."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
if ! curl -sS "wttr.in/?0&m"; then
|
||||
log_error "Failed to fetch weather."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user