Skip to content

Commit

Permalink
tool messages (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
islemci authored Dec 7, 2024
2 parents f3e638c + 8c2b589 commit 8006f22
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,9 @@ $ cliwrap

to get your wrapped everywhere!

### Custom messages for specific commands/tools

Motivating and positive messages about usage of tools like `ls`, `brew` etc. will be displayed if one of them is a top tool.

### License
This project is licensed under the MIT License. You can check out the conditions [here.](LICENSE)
34 changes: 31 additions & 3 deletions cliwrap
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,41 @@ EOF
display_table() {
local title="$1"
local data="$2"
local suppress_message="$3"

echo -e "\n${MAGENTA}${title}${RESET}"
echo -e "${YELLOW}---------------------------------${RESET}"
echo -e "${CYAN}Usage Count | Command${RESET}"
echo -e "${YELLOW}---------------------------------${RESET}"
echo -e "$data"
echo -e "${YELLOW}---------------------------------${RESET}\n"

if [[ "$suppress_message" != "true" ]]; then
# Extract the most used command/tool
local top_item
top_item=$(echo "$data" | head -n 1 | awk '{print $2}')

# Custom messages for specific commands/tools
if [[ "$top_item" == "git" ]]; then
echo -e "${YELLOW}Great! You're a git master! Keep version controlling like a pro.${RESET}"
elif [[ "$top_item" == "ls" ]]; then
echo -e "${YELLOW}Looks like you're exploring a lot of directories. Neat!${RESET}"
elif [[ "$top_item" == "cd" ]]; then
echo -e "${YELLOW}Navigating through the filesystem like a champ!${RESET}"
elif [[ "$top_item" == "python" ]]; then
echo -e "${YELLOW}Python enthusiast detected! Keep coding.${RESET}"
elif [[ "$top_item" == "vim" || "$top_item" == "nano" ]]; then
echo -e "${YELLOW}Spending quality time editing files, I see!${RESET}"
elif [[ "$top_item" == "apt" || "$top_item" == "brew" || "$top_item" == "pacman" || "$top_item" == "yay" ]]; then
echo -e "${YELLOW}You like download new packages and apps, am I correct?${RESET}"
elif [[ "$top_item" == "cliwrap" || "$top_item" == "./cliwrap" ]]; then
echo -e "${YELLOW}Your top tool is CLIwrap? Thank you for the interest!${RESET}"
elif [[ "$top_item" == "code" ]]; then
echo -e "${YELLOW}VSCode? Do you really program that much?${RESET}"
else
echo -e "${YELLOW}Your top tool is '$top_item'. Keep rocking your terminal!${RESET}"
fi
fi
}

# Display help message
Expand Down Expand Up @@ -168,12 +196,12 @@ main() {
# Top tools
local top_tools
top_tools=$(parse_history "$history_data")
display_table "Top Tools" "$top_tools"
display_table "Top Tools" "$top_tools" "true"

# Top full commands
local top_commands
top_commands=$(parse_full_commands "$history_data")
display_table "Top Full Commands" "$top_commands"
display_table "Top Full Commands" "$top_commands" "false"

# Total commands
if [[ "$history_file" == *"fish_history" ]]; then
Expand All @@ -187,4 +215,4 @@ main() {
fi
}

main "$@"
main "$@"

0 comments on commit 8006f22

Please sign in to comment.