Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions dmenu_tgit
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#!/bin/bash
#!/bin/sh

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"'
branches="$(cd "$path" && git branch -r)"
branch=$(print '%s' "$branches" | dmenu -i -p Checkout:)
x-terminal-emulator -e "sh -c "cd "$path" && git "$option $branch"; "$SHELL"""
}

options_menu(){
[[ -n $repo ]] || return 1
[ -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
prompt="$(tgit-status "$path") $repo"
option=$(printf '%b' "$git_options" | dmenu -i -p "$prompt:")
[ -n "$option" ] || return 1
case "$option" in
"checkout")
# branches_menu
;;
"open")
codium $path
codium "$path"
;;
*)
x-terminal-emulator -e 'sh -c "cd '$path' && git '$option'; $SHELL"'
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
repo=$(printf '%b' ">> UPDATE\n$(tgit)" | dmenu -i -p "$main_prompt": | awk '{print $2}')
[ -n "$repo" ] || exit
[ "$repo" = "UPDATE" ] && tgit -u && return 1
return 0
}

Expand Down
31 changes: 16 additions & 15 deletions tgit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

#This file is part of the TinyTools distribution (https://github.com/Calebe94/TinyTools).
#Copyright (C) TinyTools
Expand All @@ -19,35 +19,35 @@ 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")
repos=$(find "$HOME" -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1')
[ -n "$ignore_regex" ] && repos=$(printf '%b' "$repos" | grep -E -v "$ignore_regex")
touch /tmp/repos.dat
echo -e "$repos" > /tmp/repos.dat
printf '%b' "$repos" > /tmp/repos.dat
}

get_repos(){
if [ -f "/tmp/repos.dat" ]; then
echo -e "$(cat "/tmp/repos.dat")"
printf '%b' "$(cat "/tmp/repos.dat")"
else
update && echo -e "$(cat "/tmp/repos.dat")"
update && printf '%b' "$(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/"/''}"
cd "$i" || printf "git directory not found"
if [ "$(git rev-parse --git-dir)" = ".git" ]; then
status=$(tgit-status "$i" "$1")
name=$(printf '%s' "$i" | sed "s $HOME/ " )
list="$list\n[$status] $name"
fi
done
tmpfile=$(mktemp)
echo -e "$list" >> $tmpfile
list=$(column $tmpfile -t)
printf '%b' "$list" >> "$tmpfile"
list=$(column "$tmpfile" -t)
rm "$tmpfile"
echo -e "$list"
printf '%b' "$list"
}

repos=$(get_repos)
Expand All @@ -56,7 +56,8 @@ while getopts uc option
do
case "${option}" in
u) update && exit;;
c) echo -e "$(list -c)" && exit ;;
c) printf '%b\n' "$(list -c)" && exit ;;
*) usage; exit 1 ;;
esac
done
echo -e "$(list)"
printf '%b\n' "$(list)"
59 changes: 37 additions & 22 deletions tgit-status
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
# Git status
#
Expand Down Expand Up @@ -47,74 +47,89 @@ 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
if echo "$INDEX" | command grep -E '^\?\? ' > /dev/null 2>&1
then
git_status="$SPACESHIP_GIT_STATUS_UNTRACKED$git_status"
fi

# Check for staged files
if $(echo "$INDEX" | command grep '^A[ MDAU] ' &> /dev/null); then
if echo "$INDEX" | command grep '^A[ MDAU] ' > /dev/null 2>&1
then
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
elif $(echo "$INDEX" | command grep '^M[ MD] ' &> /dev/null); then
elif echo "$INDEX" | command grep '^M[ MD] ' > /dev/null 2>&1
then
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
elif $(echo "$INDEX" | command grep '^UA' &> /dev/null); then
elif echo "$INDEX" | command grep '^UA' > /dev/null 2>&1
then
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
fi

# Check for modified files
if $(echo "$INDEX" | command grep '^[ MARC]M ' &> /dev/null); then
if echo "$INDEX" | command grep '^[ MARC]M ' > /dev/null 2>&1
then
git_status="$SPACESHIP_GIT_STATUS_MODIFIED$git_status"
fi

# Check for renamed files
if $(echo "$INDEX" | command grep '^R[ MD] ' &> /dev/null); then
if echo "$INDEX" | command grep '^R[ MD] ' > /dev/null 2>&1
then
git_status="$SPACESHIP_GIT_STATUS_RENAMED$git_status"
fi

# Check for deleted files
if $(echo "$INDEX" | command grep '^[MARCDU ]D ' &> /dev/null); then
if echo "$INDEX" | command grep '^[MARCDU ]D ' > /dev/null 2>&1
then
git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status"
elif $(echo "$INDEX" | command grep '^D[ UM] ' &> /dev/null); then
elif echo "$INDEX" | command grep '^D[ UM] ' > /dev/null 2>&1
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
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
if echo "$INDEX" | command grep '^U[UDA] ' > /dev/null 2>&1
then
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
elif $(echo "$INDEX" | command grep '^AA ' &> /dev/null); then
elif echo "$INDEX" | command grep '^AA ' > /dev/null 2>&1
then
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
elif $(echo "$INDEX" | command grep '^DD ' &> /dev/null); then
elif echo "$INDEX" | command grep '^DD ' > /dev/null 2>&1
then
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
elif $(echo "$INDEX" | command grep '^[DA]U ' &> /dev/null); then
elif echo "$INDEX" | command grep '^[DA]U ' > /dev/null 2>&1
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
if echo "$INDEX" | command grep '^## [^ ]\+ .*ahead' > /dev/null 2>&1
then
is_ahead=true
fi

# Check whether branch is behind
is_behind=false
if $(echo "$INDEX" | command grep '^## [^ ]\+ .*behind' &> /dev/null); then
if echo "$INDEX" | command grep '^## [^ ]\+ .*behind' > /dev/null 2>&1
then
is_behind=true
fi

# Check wheather branch has diverged
if [[ "$is_ahead" == true && "$is_behind" == true ]]; then
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"
[ "$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"
if [ "$2" = "-c" ]; then
printf '%b' "$git_status\n"
else
echo $(echo -e "$git_status" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")
printf '%b' "$git_status\n" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g"
fi