[Bin] add kamoji generator
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Lucien Cartier-Tilet 2023-05-28 16:33:49 +02:00
parent 440ebe4a5d
commit 4e2c08c71c
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 57 additions and 0 deletions

View File

@ -1,3 +1,7 @@
#!/bin/sh
. "$HOME"/.profile.private
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"

View File

@ -302,6 +302,59 @@ NB_CONTAINERS=$(docker ps -q | wc -l | tr -d '\n')
printf "^f3^f0 %d" $NB_CONTAINERS
#+end_src
** Kamoji Generator
:PROPERTIES:
:CUSTOM_ID: cliutilitiesKamojiGenerator-sqvh17015uj0
:HEADER-ARGS: :shebang "#!/usr/bin/env sh" :tangle ~/.local/bin/kamoji
:END:
This script comes straight from [[https://charm.sh/blog/kamoji-generator/][this blog post]] and generates kamoji. I
modified it a bit in order to work with either =xclipboard= or =wl-copy=
depending on whether I am in a X.org session or a Wayland session.
Note that it requires the =OPENAI_API_KEY= environment variable to be
set with a valid OpenAI key.
#+begin_src bash
# If the user passes '-h', '--help', or 'help' print out a little bit of help.
# text.
case "$1" in
"-h" | "--help" | "help")
printf 'Generate kaomojis on request.\n\n'
printf 'Usage: %s [kind]\n' "$(basename "$0")"
exit 1
;;
esac
# The user can pass an argument like "bear" or "angry" to specify the general
# kind of Kaomoji produced.
sentiment=""
if [[ $1 != "" ]]; then
sentiment=" $1"
fi
# Ask mods to generate Kaomojis. Save the output in a variable.
kaomoji="$(mods "generate 10${sentiment} kaomojis. number them and put each one on its own line.")"
if [[ $kaomoji == "" ]]; then
exit 1
fi
# Pipe mods output to gum so the user can choose the perfect kaomoji. Save that
# choice in a variable. Also note that we're using cut to drop the item number
# in front of the Kaomoji.
choice="$(echo "$kaomoji" | gum choose | cut -d ' ' -f 2)"
if [[ $choice == "" ]]; then
exit 1
fi
# If the current session is Wayland, copy with wl-copy, otherwise copy with xclipboard
if [ "$XDG_SESSION_TYPE" = "wayland" ]
then printf '%s' "$choice" | wc-copy # X11
else printf '%s' "$choice" | xclip -sel clip # Wayland
fi
# We're done!
printf 'Copied %s to the clipboard\n' "$choice"
#+end_src
** mu-unread
:PROPERTIES:
:HEADER-ARGS: :shebang "#!/usr/bin/env sh" :tangle ~/.local/bin/mu-unread