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/README.md b/tgit/README.md new file mode 100644 index 0000000..34f5873 --- /dev/null +++ b/tgit/README.md @@ -0,0 +1,29 @@ +# `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 + +# 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). diff --git a/tgit/dmenu_tgit b/tgit/dmenu_tgit new file mode 100755 index 0000000..0fa7ff0 --- /dev/null +++ b/tgit/dmenu_tgit @@ -0,0 +1,46 @@ +#!/bin/bash + +main_prompt="Repositories" +git_options="open\nstatus\ndiff\ncheckout" + +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 "$git_options" | dmenu -i -p "$prompt:") + [[ -n $option ]] || return 1 + case "$option" in + "checkout") + # branches_menu + ;; + "open") + codium $path + ;; + *) + x-terminal-emulator -e 'sh -c "cd '$path' && git '$option'; $SHELL"' + ;; + esac + return 0 +} + +repos_menu(){ + repo="" + repo=$(echo -e ">> UPDATE\n$(tgit)" | dmenu -i -p "$main_prompt": | awk '{print $2}') + [[ -n $repo ]] || exit + [[ $repo == "UPDATE" ]] && tgit -u && return 1 + return 0 +} + +while true; do + repos_menu && break +done + +options_menu + + diff --git a/tgit/tgit b/tgit/tgit new file mode 100755 index 0000000..6d4b182 --- /dev/null +++ b/tgit/tgit @@ -0,0 +1,62 @@ +#!/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' + +update() { + 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 +} + +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 + +