From 4dfb7ac4dba0840ca57a46dfb89c5cc20fd06d06 Mon Sep 17 00:00:00 2001 From: Kevin Puertas Date: Tue, 28 Feb 2017 20:46:47 +0100 Subject: [PATCH] Ident file and grammar fix --- jka-toolkit/gitdit | 266 +++++++++++++++++++++++---------------------- 1 file changed, 134 insertions(+), 132 deletions(-) diff --git a/jka-toolkit/gitdit b/jka-toolkit/gitdit index 3b71e7e..2303fd5 100755 --- a/jka-toolkit/gitdit +++ b/jka-toolkit/gitdit @@ -13,137 +13,139 @@ else #Else, all other options actual2=$(git branch --list | grep "^*" | cut -f2 -d" ") #Current branch name fi if [ ! -z $gitopt ];then #No canceled -case $gitopt in - #Not staying in a git repo - "i") - gitdir=`dialog --stdout --inputbox "Repo directory" 10 60 "."` - if [ $(echo $gitdir | cut -f1 -d"/") = "~" ];then #~ don't understand like $HOME - gitdirdef="$HOME" - for (( i=2; i<=$cant; i++ )) - do - gitdirdef="$gitdirdef/$(echo $gitdir | cut -f$i -d"/")" - done -elif [ $(echo $gitdit | cut -f1 -d"/") = "." ];then - gitdirdef=$(pwd) - for (( i=1; i<=$cant; i++ )) - do - gitdirdef="$gitdirdef/$(echo $gitdir | cut -f$i -d"/")" - done -fi -if [ ! -d $gitdir ];then - mkdir -p $gitdirdef -fi -if [ $? -eq 1 ];then - echo "You dont have permission to write in this directory" >> /dev/stderr -else - cd $gitdirdef - git init -fi -;; -"c") -giturl=`dialog --stdout --inputbox "URL del git" 10 60` -if [ -z $giturl ];then - echo "No repository there." - exit -fi -git clone $giturl -;; -#Staying in a git repo -"p") -git pull $actual;; -"s") -estado=$(git status | grep -E '(^Changes|^Untracked)' ) #It need to commit something? -if [ "$estado" ];then #When is necesary commit -commit=`dialog --stdout --inputbox "Changes text: " 10 50 "changes"` -if [[ -z $commit ]];then - commit="changes" -fi -git add -A && git commit -m "$commit" && git push $actual -else #Nothing to commit, only push - git push $actual -fi -;; -"t") -commit=`dialog --stdout --inputbox "Changes text: " 10 50 "changes"` -if [[ -z $commit ]];then - commit="changes" -fi -git add -A && git commit -m "$commit" -;; -"b") -howopt=`dialog --stdout --scrollbar --menu "Change branch" 0 0 6 c "Only change branch" u "Change branch and update it"` -if [ -z $howopt ];then - exit -fi -j=0 -rama="" -#Loop to create dialog whith all branches (except the current) -for i in $(git branch -a | grep -v "^*" | grep -v "HEAD \->") -do - aux2=0 - if [ -z $(echo $i | grep -o "remotes") ];then - aux=$i - aux2=1 - else - aux=$(echo $i | cut -f3 -d"/") - error=0 #If 1 aux is yet in lista array - for (( i=0;i<${#lista[@]} && error==0;i++ )) - do - if [ $aux == ${lista[$i]} -o $aux = $actual2 ];then - error=1 + case $gitopt in + #Options not in a git repo + "i") + gitdir=`dialog --stdout --inputbox "Repo directory" 10 60 "."` + if [ $(echo $gitdir | cut -f1 -d"/") = "~" ];then #~ don't understand like $HOME + gitdirdef="$HOME" + for (( i=2; i<=$cant; i++ )) + do + gitdirdef="$gitdirdef/$(echo $gitdir | cut -f$i -d"/")" + done + elif [ $(echo $gitdit | cut -f1 -d"/") = "." ];then + gitdirdef=$(pwd) + for (( i=1; i<=$cant; i++ )) + do + gitdirdef="$gitdirdef/$(echo $gitdir | cut -f$i -d"/")" + done fi - done - if [ $error -eq 0 ];then - aux2=1 - fi - fi - if [ $aux2 -eq 1 ];then - rama="$rama $j $aux" - lista[$j]=$aux #Array with the names of branches - let j++ - fi -done -ramificacion=`dialog --stdout --scrollbar --menu "Select branch to goto" 0 0 6 $rama` -if [ ! -z $ramificacion ];then - git checkout ${lista[$ramificacion]} - if [ $howopt = "u" ];then - git pull origin ${lista[$ramificacion]} - fi -fi -;; -"n") -NewBranch=`dialog --stdout --inputbox "Name of the new branch" 10 50 "New branch"` -if [ ! -z $NewBranch ];then - git checkout -b $NewBranch -fi -;; -"m") -j=0 -rama="" -for i in $(git branch --list | grep "^*" -v ) -do - if [ $i != "*" ];then - rama="$rama $j $i" - lista[$j]=$i - let j++ - fi -done -merges=`dialog --stdout --scrollbar --menu "Select branch for merge to $(git branch --list | grep "^*" | cut -f2 -d" ")" 0 0 6 $rama` -if [ ! -z $merges ];then - git merge ${lista[$merges]} - git push $actual -fi -;; -"d") -var=1 -while [[ $var -eq 1 ]]; do - if [[ $(ls -a | grep .git) ]]; then - var=0 - else - cd .. - fi -done -git checkout .; -;; -esac + if [ ! -d $gitdir ];then + mkdir -p $gitdirdef + fi + if [ $? -eq 1 ];then + echo "You dont have permission to write in this directory" >> /dev/stderr + else + cd $gitdirdef + git init + fi + ;; + "c") + giturl=`dialog --stdout --inputbox "git URL: " 10 60` + if [ -z $giturl ];then + echo "No URL specified." + exit + fi + git clone $giturl + ;; + + + #Options of a git repo + "p") + git pull $actual;; + "s") + estado=$(git status | grep -E '(^Changes|^Untracked)' ) #It need to commit something? + if [ "$estado" ];then #When is necesary commit + commit=`dialog --stdout --inputbox "Changes text: " 10 50 "changes"` + if [[ -z $commit ]];then + commit="changes" + fi + git add -A && git commit -m "$commit" && git push $actual + else #Nothing to commit, only push + git push $actual + fi + ;; + "t") + commit=`dialog --stdout --inputbox "Changes text: " 10 50 "changes"` + if [[ -z $commit ]];then + commit="changes" + fi + git add -A && git commit -m "$commit" + ;; + "b") + howopt=`dialog --stdout --scrollbar --menu "Change branch" 0 0 6 c "Only change branch" u "Change branch and update it"` + if [ -z $howopt ];then + exit + fi + j=0 + rama="" + #Loop to create dialog whith all branches (except the current) + for i in $(git branch -a | grep -v "^*" | grep -v "HEAD \->") + do + aux2=0 + if [ -z $(echo $i | grep -o "remotes") ];then + aux=$i + aux2=1 + else + aux=$(echo $i | cut -f3 -d"/") + error=0 #If 1 aux is yet in lista array + for (( i=0;i<${#lista[@]} && error==0;i++ )) + do + if [ $aux == ${lista[$i]} -o $aux = $actual2 ];then + error=1 + fi + done + if [ $error -eq 0 ];then + aux2=1 + fi + fi + if [ $aux2 -eq 1 ];then + rama="$rama $j $aux" + lista[$j]=$aux #Array with the names of branches + let j++ + fi + done + ramificacion=`dialog --stdout --scrollbar --menu "Select branch to goto" 0 0 6 $rama` + if [ ! -z $ramificacion ];then + git checkout ${lista[$ramificacion]} + if [ $howopt = "u" ];then + git pull origin ${lista[$ramificacion]} + fi + fi + ;; + "n") + NewBranch=`dialog --stdout --inputbox "Name of the new branch" 10 50 "New branch"` + if [ ! -z $NewBranch ];then + git checkout -b $NewBranch + fi + ;; + "m") + j=0 + rama="" + for i in $(git branch --list | grep "^*" -v ) + do + if [ $i != "*" ];then + rama="$rama $j $i" + lista[$j]=$i + let j++ + fi + done + merges=`dialog --stdout --scrollbar --menu "Select branch for merge to $(git branch --list | grep "^*" | cut -f2 -d" ")" 0 0 6 $rama` + if [ ! -z $merges ];then + git merge ${lista[$merges]} + git push $actual + fi + ;; + "d") + var=1 + while [[ $var -eq 1 ]]; do + if [[ $(ls -a | grep .git) ]]; then + var=0 + else + cd .. + fi + done + git checkout .; + ;; + esac fi