kaomoji.sh
This file
Path
examples/kaomoji.sh
47 lines · 1.3 KiB · Shell
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 6837ed2 point at it.
feat(deps): bump github.com/charmbracelet/bubbletea from 0.27.0 to 1.0.0 (#661)dependabot[bot]before adoption6837ed2
lines 1–47why, one step back1#!/usr/bin/env bash23# If the user passes '-h', '--help', or 'help' print out a little bit of help.4# text.5case "$1" in6 "-h" | "--help" | "help")7 printf 'Generate kaomojis on request.\n\n'8 printf 'Usage: %s [kind]\n' "$(basename "$0")"9 exit 110 ;;11esac1213# The user can pass an argument like "bear" or "angry" to specify the general14# kind of Kaomoji produced.15sentiment=""16if [[ $1 != "" ]]; then17 sentiment=" $1"18fi1920# Ask mods to generate Kaomojis. Save the output in a variable.21kaomoji="$(mods "generate 10${sentiment} kaomojis. number them and put each one on its own line.")"22if [[ $kaomoji == "" ]]; then23 exit 124fi2526# Pipe mods output to gum so the user can choose the perfect kaomoji. Save that27# choice in a variable. Also note that we're using cut to drop the item number28# in front of the Kaomoji.29choice="$(echo "$kaomoji" | gum choose | cut -d ' ' -f 2)"30if [[ $choice == "" ]]; then31 exit 132fi3334# If xsel (X11) or pbcopy (macOS) exists, copy to the clipboard. If not, just35# print the Kaomoji.36if command -v xsel &> /dev/null; then37 printf '%s' "$choice" | xclip -sel clip # X1138elif command -v pbcopy &> /dev/null; then39 printf '%s' "$choice" | pbcopy # macOS40else41 # We can't copy, so just print it out.42 printf 'Here you go: %s\n' "$choice"43 exit 044fi4546# We're done!47printf 'Copied %s to the clipboard\n' "$choice"