From f87e08ec49e292bf58da17688139c5fc1d08c4f7 Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Thu, 22 Aug 2024 19:23:57 +0200 Subject: [PATCH] feat: clean terminals now open with logo --- bin/actions/term.sh | 5 +++++ bin/dotf | 46 ++++++---------------------------------- bin/helpers/functions.sh | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 39 deletions(-) create mode 100755 bin/actions/term.sh diff --git a/bin/actions/term.sh b/bin/actions/term.sh new file mode 100755 index 0000000..e8f5850 --- /dev/null +++ b/bin/actions/term.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env zsh + +source ~/dotfiles/bin/helpers/functions.sh + +logo continue diff --git a/bin/dotf b/bin/dotf index 2a0f969..6fd7b78 100755 --- a/bin/dotf +++ b/bin/dotf @@ -2,45 +2,6 @@ source ~/dotfiles/bin/helpers/functions.sh -logo() { - tput setaf 2 - cat ~/dotfiles/bin/resources/logo.txt - println " " "cyan" - tput sgr0 - - continue_eitherway=$1 - - # Print if repo is dirty and the count of untracked files, modified files and staged files - if [[ $(git -C ~/dotfiles status --porcelain) ]]; then - printfe "%s" "yellow" "dotfiles repo is dirty " - printfe "%s" "red" "[$(git -C ~/dotfiles status --porcelain | grep -c '^??')] untracked " - printfe "%s" "yellow" "[$(git -C ~/dotfiles status --porcelain | grep -c '^ M')] modified " - printfe "%s" "green" "[$(git -C ~/dotfiles status --porcelain | grep -c '^M ')] staged " - fi - - printfe "%s" "blue" "[$(git -C ~/dotfiles rev-parse --short HEAD)] " - if [[ $(git -C ~/dotfiles log origin/master..HEAD) ]]; then - printfe "%s" "yellow" "[!] You have $(git -C ~/dotfiles log origin/master..HEAD --oneline | wc -l | tr -d ' ') commit(s) to push" - fi - println "" "normal" - - if [[ $continue_eitherway == "continue" ]]; then - return - fi - if [[ $(git -C ~/dotfiles status --porcelain) ]]; then - # Continue? - printfe "%s" "red" "Continue anyway? [y/N] " - read -k 1 - - if [[ $REPLY != "y" ]]; then - println "" "normal" - exit 0 - fi - println "" "normal" - println "" "normal" - fi -} - status() { ~/dotfiles/bin/actions/status.sh $@ } @@ -74,4 +35,11 @@ case $1 in "help"|"--help"|"") help $@ ;; + term) + ~/dotfiles/bin/actions/term.sh $@ + ;; + *) + printfe "%s\n" "red" "Unknown command $1" + help $@ + ;; esac diff --git a/bin/helpers/functions.sh b/bin/helpers/functions.sh index 6dc532d..8905c88 100755 --- a/bin/helpers/functions.sh +++ b/bin/helpers/functions.sh @@ -6,6 +6,45 @@ println() { printfe "%s\n" $color "$1" } +logo() { + tput setaf 2 + cat ~/dotfiles/bin/resources/logo.txt + println " " "cyan" + tput sgr0 + + continue_eitherway=$1 + + # Print if repo is dirty and the count of untracked files, modified files and staged files + if [[ $(git -C ~/dotfiles status --porcelain) ]]; then + printfe "%s" "yellow" "dotfiles repo is dirty " + printfe "%s" "red" "[$(git -C ~/dotfiles status --porcelain | grep -c '^??')] untracked " + printfe "%s" "yellow" "[$(git -C ~/dotfiles status --porcelain | grep -c '^ M')] modified " + printfe "%s" "green" "[$(git -C ~/dotfiles status --porcelain | grep -c '^M ')] staged " + fi + + printfe "%s" "blue" "[$(git -C ~/dotfiles rev-parse --short HEAD)] " + if [[ $(git -C ~/dotfiles log origin/master..HEAD) ]]; then + printfe "%s" "yellow" "[!] You have $(git -C ~/dotfiles log origin/master..HEAD --oneline | wc -l | tr -d ' ') commit(s) to push" + fi + println "" "normal" + + if [[ $continue_eitherway == "continue" ]]; then + return + fi + if [[ $(git -C ~/dotfiles status --porcelain) ]]; then + # Continue? + printfe "%s" "red" "Continue anyway? [y/N] " + read -k 1 + + if [[ $REPLY != "y" ]]; then + println "" "normal" + exit 0 + fi + println "" "normal" + println "" "normal" + fi +} + # print colored with printf (args: format, color, message ...) printfe() { format=$1