From 4e2c08c71c18f6048d7e310ac714428493bdfc54 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Sun, 28 May 2023 16:33:49 +0200 Subject: [PATCH] [Bin] add kamoji generator --- .profile | 4 ++++ org/config/bin.org | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/.profile b/.profile index 4f8cad1..6c3ff2c 100644 --- a/.profile +++ b/.profile @@ -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" diff --git a/org/config/bin.org b/org/config/bin.org index dd24cae..8802d30 100644 --- a/org/config/bin.org +++ b/org/config/bin.org @@ -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