From 5d8955751b01420e80b61dab19cf62d7b1ba665e Mon Sep 17 00:00:00 2001 From: gabo Date: Thu, 18 Feb 2021 21:14:55 -0300 Subject: [PATCH 01/16] updated Makefile for tgit --- Makefile | 11 ++++- tgit/dmenu_tgit | 24 ++++++++++ tgit/tgit | 45 +++++++++++++++++ tgit/tgit_status | 122 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 200 insertions(+), 2 deletions(-) create mode 100755 tgit/dmenu_tgit create mode 100755 tgit/tgit create mode 100755 tgit/tgit_status diff --git a/Makefile b/Makefile index 7565728..54320e5 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,13 @@ tsearch: ${CONFIG_FOLDER} ${BIN_FOLDER} tyaml install tsearch/params.yaml ${CONFIG_FOLDER} @echo "done!" +tgit: ${CONFIG_FOLDER} ${BIN_FOLDER} + @echo "Installing tgit..." + install -m 555 tgit/tgit ${BIN_FOLDER} + install -m 555 tgit/dmenu_tgit ${BIN_FOLDER} + install -m 555 tgit/tgit_status ${BIN_FOLDER} + @echo "done!" + tpomodoro: ${CONFIG_FOLDER} ${BIN_FOLDER} @echo "Installing tpomodoro..." install -m 555 tpomodoro/tpomodoro ${BIN_FOLDER} @@ -80,7 +87,7 @@ uninstall: rm -f ${BIN_FOLDER}/tprogbar @echo "done!" -install: tsearch ttodo tmenu tyaml tnotes tgoeswall tpomodoro tprogbar +install: tsearch ttodo tmenu tyaml tnotes tgoeswall tpomodoro tprogbar tgit @echo "tinytools installed successfully!" -.PHONY: install tsearch tpomodoro ttodo tmenu tyaml tnotes tgoeswall uninstall tprogbar +.PHONY: install tsearch tpomodoro ttodo tmenu tyaml tnotes tgoeswall uninstall tprogbar tgit diff --git a/tgit/dmenu_tgit b/tgit/dmenu_tgit new file mode 100755 index 0000000..e196185 --- /dev/null +++ b/tgit/dmenu_tgit @@ -0,0 +1,24 @@ +#!/bin/bash + +repo=$(echo "$(tgit)" | dmenu -i -p Repos: | awk '{print $2}') + +[[ -n $repo ]] || exit +path="$HOME/$repo" +prompt=$(print "$repo" | awk -F'/' 'NF>1{print $(NF)}') && prompt="$prompt [$(tgit_status $path)]:" +options="open\nstatus\ndiff\ncheckout" +option=$(echo -e "$options" | dmenu -i -p "$prompt") + +[[ -n $option ]] || exit +case "$option" in + "checkout") + branches="$(cd $path && git branch -r)" + branch=$(echo -e "$branches" | dmenu -i -p Checkout:) + x-terminal-emulator -e 'bash -c "cd '$path' && git '$option $branch'; zsh"' + ;; + "open") + codium $path + ;; + *) + x-terminal-emulator -e 'bash -c "cd '$path' && git '$option'; zsh"' + ;; +esac \ No newline at end of file diff --git a/tgit/tgit b/tgit/tgit new file mode 100755 index 0000000..124a723 --- /dev/null +++ b/tgit/tgit @@ -0,0 +1,45 @@ +#!/bin/bash + +repos='' + +update() { + repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1' | grep -E -v 'vim|antigen') + touch /tmp/repos.dat + echo -e "$repos" > /tmp/repos.dat +} + +get_repos(){ + if [ -f "/tmp/repos.dat" ]; then + echo -e "$(cat "/tmp/repos.dat")" + else + update && echo -e "$(cat "/tmp/repos.dat")" + fi +} + +list() { + for i in $repos + do + cd $i + if [[ "$(git rev-parse --git-dir)" == ".git" ]]; then + status=$(tgit_status $i $1) + name="${i/"$HOME/"/''}" + list="$list\n[$status] $name" + fi + done + tmpfile=$(mktemp) + echo -e "$list" >> $tmpfile + list=$(column $tmpfile -t) + rm "$tmpfile" + echo -e "$list" +} + +repos=$(get_repos) + +while getopts uc option +do + case "${option}" in + u) update && exit;; + c) echo -e "$(list -c)" && exit ;; + esac +done +echo -e "$(list)" \ No newline at end of file diff --git a/tgit/tgit_status b/tgit/tgit_status new file mode 100755 index 0000000..c46cf87 --- /dev/null +++ b/tgit/tgit_status @@ -0,0 +1,122 @@ +#!/bin/bash +# +# Git status +# + +# ------------------------------------------------------------------------------ +# Configuration +# ------------------------------------------------------------------------------ +RED='\033[0;31m' +CYAN='\033[0;36m' +LIGHT_GREEN='\033[1;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +SPACESHIP_GIT_STATUS_SHOW="${SPACESHIP_GIT_STATUS_SHOW=true}" +SPACESHIP_GIT_STATUS_PREFIX="${SPACESHIP_GIT_STATUS_PREFIX=" ["}" +SPACESHIP_GIT_STATUS_SUFFIX="${SPACESHIP_GIT_STATUS_SUFFIX="]"}" +SPACESHIP_GIT_STATUS_COLOR="${SPACESHIP_GIT_STATUS_COLOR="red"}" +SPACESHIP_GIT_STATUS_UNTRACKED="${SPACESHIP_GIT_STATUS_UNTRACKED="?"}" +SPACESHIP_GIT_STATUS_ADDED="${SPACESHIP_GIT_STATUS_ADDED="${LIGHT_GREEN}+${NC}"}" +SPACESHIP_GIT_STATUS_MODIFIED="${SPACESHIP_GIT_STATUS_MODIFIED="${YELLOW}!${NC}"}" +SPACESHIP_GIT_STATUS_RENAMED="${SPACESHIP_GIT_STATUS_RENAMED="»"}" +SPACESHIP_GIT_STATUS_DELETED="${SPACESHIP_GIT_STATUS_DELETED="${RED}✘${NC}"}" +SPACESHIP_GIT_STATUS_STASHED="${SPACESHIP_GIT_STATUS_STASHED="$"}" +SPACESHIP_GIT_STATUS_UNMERGED="${SPACESHIP_GIT_STATUS_UNMERGED="="}" +SPACESHIP_GIT_STATUS_AHEAD="${SPACESHIP_GIT_STATUS_AHEAD="${CYAN}⇡${NC}"}" +SPACESHIP_GIT_STATUS_BEHIND="${SPACESHIP_GIT_STATUS_BEHIND="⇣"}" +SPACESHIP_GIT_STATUS_DIVERGED="${SPACESHIP_GIT_STATUS_DIVERGED="⇕"}" + +# ------------------------------------------------------------------------------ +# Section +# ------------------------------------------------------------------------------ + +# We used to depend on OMZ git library, +# But it doesn't handle many of the status indicator combinations. +# Also, It's hard to maintain external dependency. +# See PR #147 at https://git.io/vQkkB +# See git help status to know more about status formats +# spaceship_git_status() { +# [[ $SPACESHIP_GIT_STATUS_SHOW == false ]] && return + +# spaceship::is_git || return + +INDEX='' +git_status="" + +INDEX=$(cd "$1" && command git status --porcelain -b 2> /dev/null) + +# Check for untracked files +if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNTRACKED$git_status" +fi + +# Check for staged files +if $(echo "$INDEX" | command grep '^A[ MDAU] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" +elif $(echo "$INDEX" | command grep '^M[ MD] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" +elif $(echo "$INDEX" | command grep '^UA' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" +fi + +# Check for modified files +if $(echo "$INDEX" | command grep '^[ MARC]M ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_MODIFIED$git_status" +fi + +# Check for renamed files +if $(echo "$INDEX" | command grep '^R[ MD] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_RENAMED$git_status" +fi + +# Check for deleted files +if $(echo "$INDEX" | command grep '^[MARCDU ]D ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status" +elif $(echo "$INDEX" | command grep '^D[ UM] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status" +fi + +# Check for stashes +if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then + git_status="$SPACESHIP_GIT_STATUS_STASHED$git_status" +fi + +# Check for unmerged files +if $(echo "$INDEX" | command grep '^U[UDA] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" +elif $(echo "$INDEX" | command grep '^AA ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" +elif $(echo "$INDEX" | command grep '^DD ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" +elif $(echo "$INDEX" | command grep '^[DA]U ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" +fi + +# Check whether branch is ahead +is_ahead=false +if $(echo "$INDEX" | command grep '^## [^ ]\+ .*ahead' &> /dev/null); then + is_ahead=true +fi + +# Check whether branch is behind +is_behind=false +if $(echo "$INDEX" | command grep '^## [^ ]\+ .*behind' &> /dev/null); then + is_behind=true +fi + +# Check wheather branch has diverged +if [[ "$is_ahead" == true && "$is_behind" == true ]]; then + git_status="$SPACESHIP_GIT_STATUS_DIVERGED$git_status" +else + [[ "$is_ahead" == true ]] && git_status="$SPACESHIP_GIT_STATUS_AHEAD$git_status" + [[ "$is_behind" == true ]] && git_status="$SPACESHIP_GIT_STATUS_BEHIND$git_status" +fi + +if [[ "$2" == "-c" ]]; then + echo -e "$git_status" +else + echo $(echo -e "$git_status" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g") +fi + + From 5cc86cf31561fcd089bd9f7cf7a9993c247e7d0b Mon Sep 17 00:00:00 2001 From: gabo Date: Thu, 18 Feb 2021 22:46:37 -0300 Subject: [PATCH 02/16] Fixed shell for git execution + added repo ignore regex --- tgit/dmenu_tgit | 4 ++-- tgit/tgit | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tgit/dmenu_tgit b/tgit/dmenu_tgit index e196185..c0ae2c1 100755 --- a/tgit/dmenu_tgit +++ b/tgit/dmenu_tgit @@ -13,12 +13,12 @@ case "$option" in "checkout") branches="$(cd $path && git branch -r)" branch=$(echo -e "$branches" | dmenu -i -p Checkout:) - x-terminal-emulator -e 'bash -c "cd '$path' && git '$option $branch'; zsh"' + x-terminal-emulator -e 'sh -c "cd '$path' && git '$option $branch'; $SHELL"' ;; "open") codium $path ;; *) - x-terminal-emulator -e 'bash -c "cd '$path' && git '$option'; zsh"' + x-terminal-emulator -e 'sh -c "cd '$path' && git '$option'; $SHELL"' ;; esac \ No newline at end of file diff --git a/tgit/tgit b/tgit/tgit index 124a723..7753870 100755 --- a/tgit/tgit +++ b/tgit/tgit @@ -1,9 +1,11 @@ #!/bin/bash repos='' +ignore_regex='antigen|vim' update() { - repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1' | grep -E -v 'vim|antigen') + repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1') + [[ -n $ignore_regex ]] && repos=$(echo -e "$repos" | grep -E -v "$ignore_regex") touch /tmp/repos.dat echo -e "$repos" > /tmp/repos.dat } From 17e2513fe56525eb09dcbe09d8d5e7e7404a4334 Mon Sep 17 00:00:00 2001 From: gabo Date: Wed, 9 Dec 2020 19:18:27 -0300 Subject: [PATCH 03/16] added tgit --- tgit/tgit | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 tgit/tgit diff --git a/tgit/tgit b/tgit/tgit new file mode 100755 index 0000000..f37268e --- /dev/null +++ b/tgit/tgit @@ -0,0 +1,16 @@ +#!/bin/bash + +repos=$(find $HOME -name ".git") + +repo=$(echo -e "$repos" | dmenu -i -p Repos:) + +if [ -n "$repo" ]; then + prompt=$(echo "$repo" | awk -F'/' 'NF>1{print $(NF-1)":"}') + options="status\ndiff\ncheckout" + + option=$(echo -e "$options" | dmenu -i -p "$prompt") + + command="git --git-dir=$repo -C $repo $option" + echo $command + # eval "${command[@]}" & +fi \ No newline at end of file From 88c58689bb7da599a1720920f7e1a2b85dc8e7af Mon Sep 17 00:00:00 2001 From: gabo Date: Sat, 12 Dec 2020 16:57:47 -0300 Subject: [PATCH 04/16] added initial checkout implementation --- tgit/tgit | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tgit/tgit b/tgit/tgit index f37268e..e4b855a 100755 --- a/tgit/tgit +++ b/tgit/tgit @@ -1,16 +1,27 @@ #!/bin/bash repos=$(find $HOME -name ".git") +repos=$(echo "$repos" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1') repo=$(echo -e "$repos" | dmenu -i -p Repos:) if [ -n "$repo" ]; then - prompt=$(echo "$repo" | awk -F'/' 'NF>1{print $(NF-1)":"}') + prompt=$(echo "$repo" | awk -F'/' 'NF>1{print $(NF)":"}') options="status\ndiff\ncheckout" - option=$(echo -e "$options" | dmenu -i -p "$prompt") - command="git --git-dir=$repo -C $repo $option" - echo $command - # eval "${command[@]}" & + case "$option" in + "checkout") + branchs="$(cd $repo && git branch -r)" + branch=$(echo -e "$branchs" | dmenu -i -p Checkout:) + cd $repo && git $option + ;; + *) + cd $repo && git $option + ;; + esac + + + + # xfce4-terminal -H -e "echo bruh" fi \ No newline at end of file From 556ee93ee861a08e82b47c2e8556d828e91b505e Mon Sep 17 00:00:00 2001 From: gabo Date: Sat, 12 Dec 2020 17:20:10 -0300 Subject: [PATCH 05/16] checkout test --- tgit/tgit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tgit/tgit b/tgit/tgit index e4b855a..705b7bc 100755 --- a/tgit/tgit +++ b/tgit/tgit @@ -14,7 +14,7 @@ if [ -n "$repo" ]; then "checkout") branchs="$(cd $repo && git branch -r)" branch=$(echo -e "$branchs" | dmenu -i -p Checkout:) - cd $repo && git $option + cd $repo && git $option $branch ;; *) cd $repo && git $option From 182dba03ba149e0c31280a70b495a6ebec08b3fa Mon Sep 17 00:00:00 2001 From: gabo Date: Thu, 7 Jan 2021 18:02:47 -0300 Subject: [PATCH 06/16] updated terminal call for each command --- tgit/tgit | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tgit/tgit b/tgit/tgit index 705b7bc..ca074f9 100755 --- a/tgit/tgit +++ b/tgit/tgit @@ -14,14 +14,12 @@ if [ -n "$repo" ]; then "checkout") branchs="$(cd $repo && git branch -r)" branch=$(echo -e "$branchs" | dmenu -i -p Checkout:) - cd $repo && git $option $branch + xfce4-terminal -e 'bash -c "cd '$repo' ; git '$option $branch'; zsh"' ;; *) - cd $repo && git $option + xfce4-terminal -e 'bash -c "cd '$repo' && git '$option'; zsh"' ;; esac - - # xfce4-terminal -H -e "echo bruh" fi \ No newline at end of file From 36d6aff911686d0f36f7390df7b116e0d7673ef3 Mon Sep 17 00:00:00 2001 From: gabo Date: Thu, 7 Jan 2021 19:41:42 -0300 Subject: [PATCH 07/16] set xdg terminal emulator --- tgit/tgit | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tgit/tgit b/tgit/tgit index ca074f9..e2c9a49 100755 --- a/tgit/tgit +++ b/tgit/tgit @@ -14,12 +14,10 @@ if [ -n "$repo" ]; then "checkout") branchs="$(cd $repo && git branch -r)" branch=$(echo -e "$branchs" | dmenu -i -p Checkout:) - xfce4-terminal -e 'bash -c "cd '$repo' ; git '$option $branch'; zsh"' + x-terminal-emulator -e 'bash -c "cd '$repo' ; git '$option $branch'; zsh"' ;; *) - xfce4-terminal -e 'bash -c "cd '$repo' && git '$option'; zsh"' + x-terminal-emulator -e 'bash -c "cd '$repo' && git '$option'; zsh"' ;; esac - - # xfce4-terminal -H -e "echo bruh" fi \ No newline at end of file From 315657722b67d3cba3001239509b90187cd7314d Mon Sep 17 00:00:00 2001 From: gabo Date: Wed, 27 Jan 2021 23:20:16 -0300 Subject: [PATCH 08/16] separated code in files --- tgit/check_status | 121 ++++++++++++++++++++++++++++++++++++++++++++++ tgit/dmenu_tgit | 22 +++++++++ tgit/tgit | 38 +++++++-------- 3 files changed, 162 insertions(+), 19 deletions(-) create mode 100755 tgit/check_status create mode 100755 tgit/dmenu_tgit diff --git a/tgit/check_status b/tgit/check_status new file mode 100755 index 0000000..c3cb40a --- /dev/null +++ b/tgit/check_status @@ -0,0 +1,121 @@ +#!/bin/bash +# +# Git status +# + +# ------------------------------------------------------------------------------ +# Configuration +# ------------------------------------------------------------------------------ + +SPACESHIP_GIT_STATUS_SHOW="${SPACESHIP_GIT_STATUS_SHOW=true}" +SPACESHIP_GIT_STATUS_PREFIX="${SPACESHIP_GIT_STATUS_PREFIX=" ["}" +SPACESHIP_GIT_STATUS_SUFFIX="${SPACESHIP_GIT_STATUS_SUFFIX="]"}" +SPACESHIP_GIT_STATUS_COLOR="${SPACESHIP_GIT_STATUS_COLOR="red"}" +SPACESHIP_GIT_STATUS_UNTRACKED="${SPACESHIP_GIT_STATUS_UNTRACKED="?"}" +SPACESHIP_GIT_STATUS_ADDED="${SPACESHIP_GIT_STATUS_ADDED="+"}" +SPACESHIP_GIT_STATUS_MODIFIED="${SPACESHIP_GIT_STATUS_MODIFIED="!"}" +SPACESHIP_GIT_STATUS_RENAMED="${SPACESHIP_GIT_STATUS_RENAMED="»"}" +SPACESHIP_GIT_STATUS_DELETED="${SPACESHIP_GIT_STATUS_DELETED="✘"}" +SPACESHIP_GIT_STATUS_STASHED="${SPACESHIP_GIT_STATUS_STASHED="$"}" +SPACESHIP_GIT_STATUS_UNMERGED="${SPACESHIP_GIT_STATUS_UNMERGED="="}" +SPACESHIP_GIT_STATUS_AHEAD="${SPACESHIP_GIT_STATUS_AHEAD="⇡"}" +SPACESHIP_GIT_STATUS_BEHIND="${SPACESHIP_GIT_STATUS_BEHIND="⇣"}" +SPACESHIP_GIT_STATUS_DIVERGED="${SPACESHIP_GIT_STATUS_DIVERGED="⇕"}" + +# ------------------------------------------------------------------------------ +# Section +# ------------------------------------------------------------------------------ + +# We used to depend on OMZ git library, +# But it doesn't handle many of the status indicator combinations. +# Also, It's hard to maintain external dependency. +# See PR #147 at https://git.io/vQkkB +# See git help status to know more about status formats +# spaceship_git_status() { +# [[ $SPACESHIP_GIT_STATUS_SHOW == false ]] && return + +# spaceship::is_git || return + + INDEX='' + git_status="" + + + INDEX=$(cd "$1" && command git status --porcelain -b 2> /dev/null) + + # Check for untracked files + if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNTRACKED$git_status" + fi + + # Check for staged files + if $(echo "$INDEX" | command grep '^A[ MDAU] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" + elif $(echo "$INDEX" | command grep '^M[ MD] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" + elif $(echo "$INDEX" | command grep '^UA' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" + fi + + # Check for modified files + if $(echo "$INDEX" | command grep '^[ MARC]M ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_MODIFIED$git_status" + fi + + # Check for renamed files + if $(echo "$INDEX" | command grep '^R[ MD] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_RENAMED$git_status" + fi + + # Check for deleted files + if $(echo "$INDEX" | command grep '^[MARCDU ]D ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status" + elif $(echo "$INDEX" | command grep '^D[ UM] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status" + fi + + # Check for stashes + if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then + git_status="$SPACESHIP_GIT_STATUS_STASHED$git_status" + fi + + # Check for unmerged files + if $(echo "$INDEX" | command grep '^U[UDA] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" + elif $(echo "$INDEX" | command grep '^AA ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" + elif $(echo "$INDEX" | command grep '^DD ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" + elif $(echo "$INDEX" | command grep '^[DA]U ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" + fi + + # Check whether branch is ahead + is_ahead=false + if $(echo "$INDEX" | command grep '^## [^ ]\+ .*ahead' &> /dev/null); then + is_ahead=true + fi + + # Check whether branch is behind + is_behind=false + if $(echo "$INDEX" | command grep '^## [^ ]\+ .*behind' &> /dev/null); then + is_behind=true + fi + + # Check wheather branch has diverged + if [[ "$is_ahead" == true && "$is_behind" == true ]]; then + git_status="$SPACESHIP_GIT_STATUS_DIVERGED$git_status" + else + [[ "$is_ahead" == true ]] && git_status="$SPACESHIP_GIT_STATUS_AHEAD$git_status" + [[ "$is_behind" == true ]] && git_status="$SPACESHIP_GIT_STATUS_BEHIND$git_status" + fi + + echo "$git_status" +# if [[ -n $git_status ]]; then +# # Status prefixes are colorized +# spaceship::section \ +# "$SPACESHIP_GIT_STATUS_COLOR" \ +# "$SPACESHIP_GIT_STATUS_PREFIX$git_status$SPACESHIP_GIT_STATUS_SUFFIX" +# fi +# } + +# $spaceship_git_status $1 diff --git a/tgit/dmenu_tgit b/tgit/dmenu_tgit new file mode 100755 index 0000000..0d394ff --- /dev/null +++ b/tgit/dmenu_tgit @@ -0,0 +1,22 @@ +#!/bin/bash + +tgit="/home/gabo/packages/tinytools/tgit/tgit" +repo=$(echo -e "$($tgit)" | dmenu -i -p Repos: | awk '{print $2}') + +[[ -n $repo ]] || exit +path="$HOME/$repo" +prompt=$(echo "$repo" | awk -F'/' 'NF>1{print $(NF)}') && prompt="$prompt [$($check_status $path)]:" +options="status\ndiff\ncheckout" +option=$(echo -e "$options" | dmenu -i -p "$prompt") + +[[ -n $option ]] || exit +case "$option" in + "checkout") + branches="$(cd $path && git branch -r)" + branch=$(echo -e "$branches" | dmenu -i -p Checkout:) + x-terminal-emulator -e 'bash -c "cd '$path' && git '$option $branch'; zsh"' + ;; + *) + x-terminal-emulator -e 'bash -c "cd '$path' && git '$option'; zsh"' + ;; +esac \ No newline at end of file diff --git a/tgit/tgit b/tgit/tgit index e2c9a49..7fd009b 100755 --- a/tgit/tgit +++ b/tgit/tgit @@ -1,23 +1,23 @@ #!/bin/bash -repos=$(find $HOME -name ".git") -repos=$(echo "$repos" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1') +check_status="/home/gabo/packages/tinytools/tgit/check_status" +repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1') -repo=$(echo -e "$repos" | dmenu -i -p Repos:) +list() { + for i in $repos + do + cd $i + if [[ "$(git rev-parse --git-dir)" == ".git" ]]; then + status=$($check_status $i) + name="${i/"$HOME/"/''}" + list="$list\n[$status] $name" + fi + done + tmpfile=$(mktemp) + echo -e "$list" >> $tmpfile + list=$(column $tmpfile -t) + rm "$tmpfile" + echo -e "$list" +} -if [ -n "$repo" ]; then - prompt=$(echo "$repo" | awk -F'/' 'NF>1{print $(NF)":"}') - options="status\ndiff\ncheckout" - option=$(echo -e "$options" | dmenu -i -p "$prompt") - - case "$option" in - "checkout") - branchs="$(cd $repo && git branch -r)" - branch=$(echo -e "$branchs" | dmenu -i -p Checkout:) - x-terminal-emulator -e 'bash -c "cd '$repo' ; git '$option $branch'; zsh"' - ;; - *) - x-terminal-emulator -e 'bash -c "cd '$repo' && git '$option'; zsh"' - ;; - esac -fi \ No newline at end of file +list \ No newline at end of file From 56e413333bcf3091b236fa7da126c6f3bee7e8a6 Mon Sep 17 00:00:00 2001 From: gabo Date: Fri, 5 Feb 2021 20:31:34 -0300 Subject: [PATCH 09/16] added -c and -u as color and update flags, respectively --- tgit/check_status | 175 +++++++++++++++++++++++----------------------- tgit/dmenu_tgit | 10 ++- tgit/tgit | 29 +++++++- 3 files changed, 121 insertions(+), 93 deletions(-) diff --git a/tgit/check_status b/tgit/check_status index c3cb40a..c46cf87 100755 --- a/tgit/check_status +++ b/tgit/check_status @@ -6,19 +6,24 @@ # ------------------------------------------------------------------------------ # Configuration # ------------------------------------------------------------------------------ +RED='\033[0;31m' +CYAN='\033[0;36m' +LIGHT_GREEN='\033[1;32m' +YELLOW='\033[1;33m' +NC='\033[0m' SPACESHIP_GIT_STATUS_SHOW="${SPACESHIP_GIT_STATUS_SHOW=true}" SPACESHIP_GIT_STATUS_PREFIX="${SPACESHIP_GIT_STATUS_PREFIX=" ["}" SPACESHIP_GIT_STATUS_SUFFIX="${SPACESHIP_GIT_STATUS_SUFFIX="]"}" SPACESHIP_GIT_STATUS_COLOR="${SPACESHIP_GIT_STATUS_COLOR="red"}" SPACESHIP_GIT_STATUS_UNTRACKED="${SPACESHIP_GIT_STATUS_UNTRACKED="?"}" -SPACESHIP_GIT_STATUS_ADDED="${SPACESHIP_GIT_STATUS_ADDED="+"}" -SPACESHIP_GIT_STATUS_MODIFIED="${SPACESHIP_GIT_STATUS_MODIFIED="!"}" +SPACESHIP_GIT_STATUS_ADDED="${SPACESHIP_GIT_STATUS_ADDED="${LIGHT_GREEN}+${NC}"}" +SPACESHIP_GIT_STATUS_MODIFIED="${SPACESHIP_GIT_STATUS_MODIFIED="${YELLOW}!${NC}"}" SPACESHIP_GIT_STATUS_RENAMED="${SPACESHIP_GIT_STATUS_RENAMED="»"}" -SPACESHIP_GIT_STATUS_DELETED="${SPACESHIP_GIT_STATUS_DELETED="✘"}" +SPACESHIP_GIT_STATUS_DELETED="${SPACESHIP_GIT_STATUS_DELETED="${RED}✘${NC}"}" SPACESHIP_GIT_STATUS_STASHED="${SPACESHIP_GIT_STATUS_STASHED="$"}" SPACESHIP_GIT_STATUS_UNMERGED="${SPACESHIP_GIT_STATUS_UNMERGED="="}" -SPACESHIP_GIT_STATUS_AHEAD="${SPACESHIP_GIT_STATUS_AHEAD="⇡"}" +SPACESHIP_GIT_STATUS_AHEAD="${SPACESHIP_GIT_STATUS_AHEAD="${CYAN}⇡${NC}"}" SPACESHIP_GIT_STATUS_BEHIND="${SPACESHIP_GIT_STATUS_BEHIND="⇣"}" SPACESHIP_GIT_STATUS_DIVERGED="${SPACESHIP_GIT_STATUS_DIVERGED="⇕"}" @@ -36,86 +41,82 @@ SPACESHIP_GIT_STATUS_DIVERGED="${SPACESHIP_GIT_STATUS_DIVERGED="⇕"}" # spaceship::is_git || return - INDEX='' - git_status="" - - - INDEX=$(cd "$1" && command git status --porcelain -b 2> /dev/null) - - # Check for untracked files - if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_UNTRACKED$git_status" - fi - - # Check for staged files - if $(echo "$INDEX" | command grep '^A[ MDAU] ' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" - elif $(echo "$INDEX" | command grep '^M[ MD] ' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" - elif $(echo "$INDEX" | command grep '^UA' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" - fi - - # Check for modified files - if $(echo "$INDEX" | command grep '^[ MARC]M ' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_MODIFIED$git_status" - fi - - # Check for renamed files - if $(echo "$INDEX" | command grep '^R[ MD] ' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_RENAMED$git_status" - fi - - # Check for deleted files - if $(echo "$INDEX" | command grep '^[MARCDU ]D ' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status" - elif $(echo "$INDEX" | command grep '^D[ UM] ' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status" - fi - - # Check for stashes - if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then - git_status="$SPACESHIP_GIT_STATUS_STASHED$git_status" - fi - - # Check for unmerged files - if $(echo "$INDEX" | command grep '^U[UDA] ' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" - elif $(echo "$INDEX" | command grep '^AA ' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" - elif $(echo "$INDEX" | command grep '^DD ' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" - elif $(echo "$INDEX" | command grep '^[DA]U ' &> /dev/null); then - git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" - fi - - # Check whether branch is ahead - is_ahead=false - if $(echo "$INDEX" | command grep '^## [^ ]\+ .*ahead' &> /dev/null); then - is_ahead=true - fi - - # Check whether branch is behind - is_behind=false - if $(echo "$INDEX" | command grep '^## [^ ]\+ .*behind' &> /dev/null); then - is_behind=true - fi - - # Check wheather branch has diverged - if [[ "$is_ahead" == true && "$is_behind" == true ]]; then - git_status="$SPACESHIP_GIT_STATUS_DIVERGED$git_status" - else - [[ "$is_ahead" == true ]] && git_status="$SPACESHIP_GIT_STATUS_AHEAD$git_status" - [[ "$is_behind" == true ]] && git_status="$SPACESHIP_GIT_STATUS_BEHIND$git_status" - fi - - echo "$git_status" -# if [[ -n $git_status ]]; then -# # Status prefixes are colorized -# spaceship::section \ -# "$SPACESHIP_GIT_STATUS_COLOR" \ -# "$SPACESHIP_GIT_STATUS_PREFIX$git_status$SPACESHIP_GIT_STATUS_SUFFIX" -# fi -# } - -# $spaceship_git_status $1 +INDEX='' +git_status="" + +INDEX=$(cd "$1" && command git status --porcelain -b 2> /dev/null) + +# Check for untracked files +if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNTRACKED$git_status" +fi + +# Check for staged files +if $(echo "$INDEX" | command grep '^A[ MDAU] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" +elif $(echo "$INDEX" | command grep '^M[ MD] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" +elif $(echo "$INDEX" | command grep '^UA' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status" +fi + +# Check for modified files +if $(echo "$INDEX" | command grep '^[ MARC]M ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_MODIFIED$git_status" +fi + +# Check for renamed files +if $(echo "$INDEX" | command grep '^R[ MD] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_RENAMED$git_status" +fi + +# Check for deleted files +if $(echo "$INDEX" | command grep '^[MARCDU ]D ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status" +elif $(echo "$INDEX" | command grep '^D[ UM] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status" +fi + +# Check for stashes +if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then + git_status="$SPACESHIP_GIT_STATUS_STASHED$git_status" +fi + +# Check for unmerged files +if $(echo "$INDEX" | command grep '^U[UDA] ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" +elif $(echo "$INDEX" | command grep '^AA ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" +elif $(echo "$INDEX" | command grep '^DD ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" +elif $(echo "$INDEX" | command grep '^[DA]U ' &> /dev/null); then + git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status" +fi + +# Check whether branch is ahead +is_ahead=false +if $(echo "$INDEX" | command grep '^## [^ ]\+ .*ahead' &> /dev/null); then + is_ahead=true +fi + +# Check whether branch is behind +is_behind=false +if $(echo "$INDEX" | command grep '^## [^ ]\+ .*behind' &> /dev/null); then + is_behind=true +fi + +# Check wheather branch has diverged +if [[ "$is_ahead" == true && "$is_behind" == true ]]; then + git_status="$SPACESHIP_GIT_STATUS_DIVERGED$git_status" +else + [[ "$is_ahead" == true ]] && git_status="$SPACESHIP_GIT_STATUS_AHEAD$git_status" + [[ "$is_behind" == true ]] && git_status="$SPACESHIP_GIT_STATUS_BEHIND$git_status" +fi + +if [[ "$2" == "-c" ]]; then + echo -e "$git_status" +else + echo $(echo -e "$git_status" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g") +fi + + diff --git a/tgit/dmenu_tgit b/tgit/dmenu_tgit index 0d394ff..0120e18 100755 --- a/tgit/dmenu_tgit +++ b/tgit/dmenu_tgit @@ -1,12 +1,13 @@ #!/bin/bash tgit="/home/gabo/packages/tinytools/tgit/tgit" -repo=$(echo -e "$($tgit)" | dmenu -i -p Repos: | awk '{print $2}') +check_status="/home/gabo/packages/tinytools/tgit/check_status" +repo=$(echo "$($tgit)" | dmenu -i -p Repos: | awk '{print $2}') [[ -n $repo ]] || exit path="$HOME/$repo" -prompt=$(echo "$repo" | awk -F'/' 'NF>1{print $(NF)}') && prompt="$prompt [$($check_status $path)]:" -options="status\ndiff\ncheckout" +prompt=$(print "$repo" | awk -F'/' 'NF>1{print $(NF)}') && prompt="$prompt [$($check_status $path)]:" +options="open\nstatus\ndiff\ncheckout" option=$(echo -e "$options" | dmenu -i -p "$prompt") [[ -n $option ]] || exit @@ -16,6 +17,9 @@ case "$option" in branch=$(echo -e "$branches" | dmenu -i -p Checkout:) x-terminal-emulator -e 'bash -c "cd '$path' && git '$option $branch'; zsh"' ;; + "open") + codium $path + ;; *) x-terminal-emulator -e 'bash -c "cd '$path' && git '$option'; zsh"' ;; diff --git a/tgit/tgit b/tgit/tgit index 7fd009b..6362d21 100755 --- a/tgit/tgit +++ b/tgit/tgit @@ -1,14 +1,28 @@ #!/bin/bash check_status="/home/gabo/packages/tinytools/tgit/check_status" -repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1') +repos='' + +update() { + repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1') + touch /tmp/repos.dat + echo -e "$repos" > /tmp/repos.dat +} + +get_repos(){ + if [ -f "/tmp/repos.dat" ]; then + echo -e "$(cat "/tmp/repos.dat")" + else + update && echo -e "$(cat "/tmp/repos.dat")" + fi +} list() { for i in $repos do cd $i if [[ "$(git rev-parse --git-dir)" == ".git" ]]; then - status=$($check_status $i) + status=$($check_status $i $1) name="${i/"$HOME/"/''}" list="$list\n[$status] $name" fi @@ -20,4 +34,13 @@ list() { echo -e "$list" } -list \ No newline at end of file +repos=$(get_repos) + +while getopts uc option +do + case "${option}" in + u) update && exit;; + c) echo -e "$(list -c)" && exit ;; + esac +done +echo -e "$(list)" \ No newline at end of file From 5e2d2f6237ce415dd33181559750b254046702ae Mon Sep 17 00:00:00 2001 From: gabo Date: Thu, 18 Feb 2021 21:14:55 -0300 Subject: [PATCH 10/16] updated Makefile for tgit --- Makefile | 11 +++++++++-- tgit/dmenu_tgit | 6 ++---- tgit/tgit | 5 ++--- tgit/{check_status => tgit_status} | 0 4 files changed, 13 insertions(+), 9 deletions(-) rename tgit/{check_status => tgit_status} (100%) diff --git a/Makefile b/Makefile index 7565728..54320e5 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,13 @@ tsearch: ${CONFIG_FOLDER} ${BIN_FOLDER} tyaml install tsearch/params.yaml ${CONFIG_FOLDER} @echo "done!" +tgit: ${CONFIG_FOLDER} ${BIN_FOLDER} + @echo "Installing tgit..." + install -m 555 tgit/tgit ${BIN_FOLDER} + install -m 555 tgit/dmenu_tgit ${BIN_FOLDER} + install -m 555 tgit/tgit_status ${BIN_FOLDER} + @echo "done!" + tpomodoro: ${CONFIG_FOLDER} ${BIN_FOLDER} @echo "Installing tpomodoro..." install -m 555 tpomodoro/tpomodoro ${BIN_FOLDER} @@ -80,7 +87,7 @@ uninstall: rm -f ${BIN_FOLDER}/tprogbar @echo "done!" -install: tsearch ttodo tmenu tyaml tnotes tgoeswall tpomodoro tprogbar +install: tsearch ttodo tmenu tyaml tnotes tgoeswall tpomodoro tprogbar tgit @echo "tinytools installed successfully!" -.PHONY: install tsearch tpomodoro ttodo tmenu tyaml tnotes tgoeswall uninstall tprogbar +.PHONY: install tsearch tpomodoro ttodo tmenu tyaml tnotes tgoeswall uninstall tprogbar tgit diff --git a/tgit/dmenu_tgit b/tgit/dmenu_tgit index 0120e18..e196185 100755 --- a/tgit/dmenu_tgit +++ b/tgit/dmenu_tgit @@ -1,12 +1,10 @@ #!/bin/bash -tgit="/home/gabo/packages/tinytools/tgit/tgit" -check_status="/home/gabo/packages/tinytools/tgit/check_status" -repo=$(echo "$($tgit)" | dmenu -i -p Repos: | awk '{print $2}') +repo=$(echo "$(tgit)" | dmenu -i -p Repos: | awk '{print $2}') [[ -n $repo ]] || exit path="$HOME/$repo" -prompt=$(print "$repo" | awk -F'/' 'NF>1{print $(NF)}') && prompt="$prompt [$($check_status $path)]:" +prompt=$(print "$repo" | awk -F'/' 'NF>1{print $(NF)}') && prompt="$prompt [$(tgit_status $path)]:" options="open\nstatus\ndiff\ncheckout" option=$(echo -e "$options" | dmenu -i -p "$prompt") diff --git a/tgit/tgit b/tgit/tgit index 6362d21..124a723 100755 --- a/tgit/tgit +++ b/tgit/tgit @@ -1,10 +1,9 @@ #!/bin/bash -check_status="/home/gabo/packages/tinytools/tgit/check_status" repos='' update() { - repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1') + repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1' | grep -E -v 'vim|antigen') touch /tmp/repos.dat echo -e "$repos" > /tmp/repos.dat } @@ -22,7 +21,7 @@ list() { do cd $i if [[ "$(git rev-parse --git-dir)" == ".git" ]]; then - status=$($check_status $i $1) + status=$(tgit_status $i $1) name="${i/"$HOME/"/''}" list="$list\n[$status] $name" fi diff --git a/tgit/check_status b/tgit/tgit_status similarity index 100% rename from tgit/check_status rename to tgit/tgit_status From c38616ee449f41ed28dcedb50a20d4d6cf7119fc Mon Sep 17 00:00:00 2001 From: gabo Date: Thu, 18 Feb 2021 22:46:37 -0300 Subject: [PATCH 11/16] Fixed shell for git execution + added repo ignore regex --- tgit/dmenu_tgit | 4 ++-- tgit/tgit | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tgit/dmenu_tgit b/tgit/dmenu_tgit index e196185..c0ae2c1 100755 --- a/tgit/dmenu_tgit +++ b/tgit/dmenu_tgit @@ -13,12 +13,12 @@ case "$option" in "checkout") branches="$(cd $path && git branch -r)" branch=$(echo -e "$branches" | dmenu -i -p Checkout:) - x-terminal-emulator -e 'bash -c "cd '$path' && git '$option $branch'; zsh"' + x-terminal-emulator -e 'sh -c "cd '$path' && git '$option $branch'; $SHELL"' ;; "open") codium $path ;; *) - x-terminal-emulator -e 'bash -c "cd '$path' && git '$option'; zsh"' + x-terminal-emulator -e 'sh -c "cd '$path' && git '$option'; $SHELL"' ;; esac \ No newline at end of file diff --git a/tgit/tgit b/tgit/tgit index 124a723..7753870 100755 --- a/tgit/tgit +++ b/tgit/tgit @@ -1,9 +1,11 @@ #!/bin/bash repos='' +ignore_regex='antigen|vim' update() { - repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1' | grep -E -v 'vim|antigen') + repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1') + [[ -n $ignore_regex ]] && repos=$(echo -e "$repos" | grep -E -v "$ignore_regex") touch /tmp/repos.dat echo -e "$repos" > /tmp/repos.dat } From b431169455aafc64e66c02b529144afa259efb78 Mon Sep 17 00:00:00 2001 From: gabo Date: Mon, 8 Mar 2021 09:11:44 -0300 Subject: [PATCH 12/16] Added first tgit README --- tgit/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tgit/README.md diff --git a/tgit/README.md b/tgit/README.md new file mode 100644 index 0000000..5b7d1de --- /dev/null +++ b/tgit/README.md @@ -0,0 +1,19 @@ +# `tgit` +A simple script to list all the important repositories in your local system. + +``` +$ tgit +``` + +## tinytools + dmenu = :heart: + +This script supports dmenu as an interface, so you can list and manage your repos quickly through a bindkey: + +``` +$ dmenu_tgit +``` + +## dependencies: +- git +- find +- awk \ No newline at end of file From f59a84184f171717263b8429472ed742fdd0272b Mon Sep 17 00:00:00 2001 From: gabo Date: Mon, 8 Mar 2021 10:02:06 -0300 Subject: [PATCH 13/16] updated README with team and license info --- tgit/README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tgit/README.md b/tgit/README.md index 5b7d1de..34f5873 100644 --- a/tgit/README.md +++ b/tgit/README.md @@ -16,4 +16,14 @@ $ dmenu_tgit ## dependencies: - git - find -- awk \ No newline at end of file +- awk + +# Team + +| Edimar Calebe Castanho | Gabriel Gaboardi | +|:---------------------------------------------------------------------------------:|:-------------------------------------------------------------------------:| +| [Edimar Calebe Castanho (Calebe94)](https://github.com/Calebe94) | [Gabriel Gaboardi (Gabo)](https://github.com/gbgabo) | + +# License + +All software is covered under [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html). From f98aaef05084d5ed31e7f2c65de1634c83c608dd Mon Sep 17 00:00:00 2001 From: gabo Date: Mon, 8 Mar 2021 13:47:28 -0300 Subject: [PATCH 14/16] added license disclaimer on source code --- tgit/tgit | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tgit/tgit b/tgit/tgit index 7753870..6d4b182 100755 --- a/tgit/tgit +++ b/tgit/tgit @@ -1,5 +1,20 @@ #!/bin/bash +#This file is part of the TinyTools distribution (https://github.com/Calebe94/TinyTools). +#Copyright (C) TinyTools + +#This program is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, version 3 of the License. + +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with this program. If not, see . + repos='' ignore_regex='antigen|vim' From ac0bf86b79f9526bc08ff16c1e8bb4140956e0d7 Mon Sep 17 00:00:00 2001 From: gabo Date: Sun, 18 Jul 2021 16:26:48 -0300 Subject: [PATCH 15/16] added update option on dmenu --- tgit/dmenu_tgit | 56 +++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/tgit/dmenu_tgit b/tgit/dmenu_tgit index c0ae2c1..bfe7c4b 100755 --- a/tgit/dmenu_tgit +++ b/tgit/dmenu_tgit @@ -1,24 +1,40 @@ #!/bin/bash -repo=$(echo "$(tgit)" | dmenu -i -p Repos: | awk '{print $2}') - -[[ -n $repo ]] || exit -path="$HOME/$repo" -prompt=$(print "$repo" | awk -F'/' 'NF>1{print $(NF)}') && prompt="$prompt [$(tgit_status $path)]:" +is_special_input=1 options="open\nstatus\ndiff\ncheckout" -option=$(echo -e "$options" | dmenu -i -p "$prompt") -[[ -n $option ]] || exit -case "$option" in - "checkout") - branches="$(cd $path && git branch -r)" - branch=$(echo -e "$branches" | dmenu -i -p Checkout:) - x-terminal-emulator -e 'sh -c "cd '$path' && git '$option $branch'; $SHELL"' - ;; - "open") - codium $path - ;; - *) - x-terminal-emulator -e 'sh -c "cd '$path' && git '$option'; $SHELL"' - ;; -esac \ No newline at end of file +list_options(){ + path="$HOME/$repo" + prompt="$(tgit_status $path) $repo" + option=$(echo -e "$options" | dmenu -i -p "$prompt:") + [[ -n $option ]] || exit + case "$option" in + "checkout") + branches="$(cd $path && git branch -r)" + branch=$(echo -e "$branches" | dmenu -i -p Checkout:) + x-terminal-emulator -e 'sh -c "cd '$path' && git '$option $branch'; $SHELL"' + ;; + "open") + codium $path + ;; + *) + x-terminal-emulator -e 'sh -c "cd '$path' && git '$option'; $SHELL"' + ;; + esac +} + +while [ $is_special_input == 1 ]; do + repo="" + repo=$(echo -e ">> UPDATE\n$(tgit)" | dmenu -i -p Repos: | awk '{print $2}') + [[ -n $repo ]] || exit + if [[ $repo == "UPDATE" ]]; then + tgit -u + else + is_special_input=0 + list_options + fi +done + +exit + + From f5d59fc1945046bb57e91635ec3366362faa5800 Mon Sep 17 00:00:00 2001 From: gabo Date: Wed, 21 Jul 2021 18:06:23 -0300 Subject: [PATCH 16/16] refactored main loop of executions --- tgit/dmenu_tgit | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/tgit/dmenu_tgit b/tgit/dmenu_tgit index bfe7c4b..0fa7ff0 100755 --- a/tgit/dmenu_tgit +++ b/tgit/dmenu_tgit @@ -1,18 +1,23 @@ #!/bin/bash -is_special_input=1 -options="open\nstatus\ndiff\ncheckout" +main_prompt="Repositories" +git_options="open\nstatus\ndiff\ncheckout" -list_options(){ +branches_menu(){ + branches="$(cd $path && git branch -r)" + branch=$(echo -e "$branches" | dmenu -i -p Checkout:) + x-terminal-emulator -e 'sh -c "cd '$path' && git '$option $branch'; $SHELL"' +} + +options_menu(){ + [[ -n $repo ]] || return 1 path="$HOME/$repo" prompt="$(tgit_status $path) $repo" - option=$(echo -e "$options" | dmenu -i -p "$prompt:") - [[ -n $option ]] || exit + option=$(echo -e "$git_options" | dmenu -i -p "$prompt:") + [[ -n $option ]] || return 1 case "$option" in "checkout") - branches="$(cd $path && git branch -r)" - branch=$(echo -e "$branches" | dmenu -i -p Checkout:) - x-terminal-emulator -e 'sh -c "cd '$path' && git '$option $branch'; $SHELL"' + # branches_menu ;; "open") codium $path @@ -21,20 +26,21 @@ list_options(){ x-terminal-emulator -e 'sh -c "cd '$path' && git '$option'; $SHELL"' ;; esac + return 0 } -while [ $is_special_input == 1 ]; do +repos_menu(){ repo="" - repo=$(echo -e ">> UPDATE\n$(tgit)" | dmenu -i -p Repos: | awk '{print $2}') + repo=$(echo -e ">> UPDATE\n$(tgit)" | dmenu -i -p "$main_prompt": | awk '{print $2}') [[ -n $repo ]] || exit - if [[ $repo == "UPDATE" ]]; then - tgit -u - else - is_special_input=0 - list_options - fi + [[ $repo == "UPDATE" ]] && tgit -u && return 1 + return 0 +} + +while true; do + repos_menu && break done -exit +options_menu