From 888f5cb85ee1bb5962598420951f6e4c6ac5acd0 Mon Sep 17 00:00:00 2001 From: Jan Krag Date: Wed, 15 Feb 2023 00:40:27 +0100 Subject: [PATCH] WIP Gum enhanced version of chat program --- chat-gum.sh | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++ git-chatg | 1 + 2 files changed, 115 insertions(+) create mode 100755 chat-gum.sh create mode 120000 git-chatg diff --git a/chat-gum.sh b/chat-gum.sh new file mode 100755 index 0000000..0886815 --- /dev/null +++ b/chat-gum.sh @@ -0,0 +1,114 @@ +#!/usr/bin/env bash + +GREEN='\033[0;32m' +RED='\033[0;31m' +RC='\033[0m' # Reset Color +WIDTH=90 +# https://www.ditig.com/256-colors-cheat-sheet +export GUM_INPUT_CURSOR_FOREGROUND=45 # 51=Cyan1 +export GUM_INPUT_PROMPT_FOREGROUND=46 # 45=Turquoise2 + +WELCOME=$(gum style --width "$WIDTH" --align center --padding 1 --margin 0 --border double "Welcome to GitSlick, the Git based miniature chat app." ) +C1=$(gum style --underline --bold 'Commands:') + +git config alias.chatlog "log --reverse --pretty=\"format:%C(green)%aN %C(blue)[%ad]%C(reset)%n%B\" --date=relative" + +commands() { + local C2 D2 C3 D3 C4 D4 C5 D5 C6 D6 C7 D7 C8 D8 COMMANDS DESCRIBS CMDTABLE + C2=$(gum style --foreground '10' '/help') + D2=$(gum style --italic '(print list of supported commands)') + C3=$(gum style --foreground '14' '/list') + D3=$(gum style --italic '(to list channels)' ) + C4=$(gum style --foreground '14' '/switch ') + D4=$(gum style --italic '(to change #channel)') + C5=$(gum style --foreground '14' '/create ') + D5=$(gum style --italic '(to create a new #channel)') + C6=$(gum style --foreground '14' '/repeat [n]') + D6=$(gum style --italic '(repeat last n messages - default 5)') + C7=$(gum style --foreground '14' '/post') + D7=$(gum style --italic '(write a post aka. multiline message)') + C8=$(gum style --foreground '9' '/quit or /exit') + D8=$(gum style --italic '(to quit chat)') + COMMANDS=$(gum style --align left --padding "0 1" --margin 0 "$C2" "$C3" "$C4" "$C5" "$C6" "$C7" "$C8") + DESCRIBS=$(gum style --align left --padding "0 1" --margin 0 "$D2" "$D3" "$D4" "$D5" "$D6" "$D7" "$D8") + CMDTABLE=$(gum join --horizontal "$COMMANDS" "$DESCRIBS" ) + CMDBOX=$(gum style --width "$WIDTH" --border normal "$CMDTABLE") + #echo "$CMDBOX" +} +commands + +welcome() { + gum join --vertical "$WELCOME" "$C1" "$CMDBOX" + gum style --width "$WIDTH" --align left --padding "0 1" --margin "0 0" --border hidden \ + "Anything starting with a slash is a command. E.g. $(gum style --foreground '10' '/help')"\ + "Anything else is treated as a chat message. It will be commited to current dir git repo and pushed immediately to origin" \ + "with $(gum style --bold --foreground 9 "NO") safety checks or error handling." + gum style --width "$WIDTH" --align left --padding "0 1" --margin "0 0" --border rounded \ + "$(gum style --bold "NOTE"): Currently only really supports single line messages. Behaviour undefined if pasting multiline content." \ + "But you can now use the $(gum style --foreground '10' '/post') feature if you want to send multiline content." + # gum style --width "$WIDTH" --align left --padding "0 1" --margin "0 0" --border normal \ + # "NOTE: You can use $(gum style --foreground '10' '/repeat') to repeat last messages in current channel." + gum style --width "$WIDTH" --align left --padding "0 1" --margin "0 0" --border hidden \ + "You are currently in folder $(gum style --foreground '14' "$(pwd)")" \ + "And pushing to $(gum style --foreground '14' "$(git remote get-url origin --push)")" +} + +title(){ + BASE=$(basename -s .git "$(git config --get remote.origin.url)") + BRANCH=$(git branch --show-current) + TITLE="#$BRANCH @ $BASE" + printf '\033]2;%s\a' "$TITLE" + #printf "\[\e]2;%s\a\]" +} +welcome +#title +fetch_print_ff() { + gum spin --spinner dot --title Fetching -- git fetch --quiet + git chatlog "..@{u}" + git merge --ff-only --quiet +} + +# fetch_print_ff +# while true ; do +# while IFS=" " read -r -e -p "$(git branch --show-current)> " cm options; do +# fetch_print_ff +# echo +# if [ "$cm" = "" ]; then +# : +# elif [ "$cm" = "/quit" ]; then +# exit 0 +# elif [ "$cm" = "/exit" ]; then +# exit 0 +# elif [ "$cm" = "/help" ]; then +# echo "$CMDBOX" +# echo +# elif [ "$cm" = "/switch" ]; then +# git switch "$options" +# title +# echo "Showing last 5 messages in $options" +# git chatlog -5 +# elif [ "$cm" = "/list" ]; then +# echo -e "Existing channels: (use ${GREEN}/switch ${RC} to change channel" +# git branch -a +# elif [ "$cm" = "/create" ]; then +# echo "Creating new channel $options" +# git switch --quiet --orphan "$options" +# git commit --allow-empty --message "Beginning of Channel $options" +# git push --set-upstream --quiet origin "$options" +# title +# elif [ "$cm" = "/repeat" ]; then +# : "${options:=5}" +# echo -e "Repeating last $options messages in ${RED}$(git branch --show-current)${RC}" +# git chatlog "-$options" +# elif [ "$cm" = "/post" ]; then +# git commit --quiet --allow-empty +# git chatlog -1 +# git push --quiet origin +# else +# message="$cm $options" +# git commit --quiet --allow-empty --message "$message" +# git chatlog -1 +# git push --quiet origin +# fi +# done +# done diff --git a/git-chatg b/git-chatg new file mode 120000 index 0000000..2d4b544 --- /dev/null +++ b/git-chatg @@ -0,0 +1 @@ +chat-gum.sh \ No newline at end of file