diff --git a/dmenu_tgit b/dmenu_tgit index dcb5c42..076cbe8 100755 --- a/dmenu_tgit +++ b/dmenu_tgit @@ -1,29 +1,29 @@ -#!/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 @@ -31,9 +31,9 @@ options_menu(){ 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 } diff --git a/tgit b/tgit index 20ed2d7..ca78e1e 100755 --- a/tgit +++ b/tgit @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh #This file is part of the TinyTools distribution (https://github.com/Calebe94/TinyTools). #Copyright (C) TinyTools @@ -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) @@ -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)" \ No newline at end of file +printf '%b\n' "$(list)" \ No newline at end of file diff --git a/tgit-status b/tgit-status index b0660d7..56fee4e 100755 --- a/tgit-status +++ b/tgit-status @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # Git status # @@ -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