From bd093290b357aa02bffde79e10ab672bc99e5cce Mon Sep 17 00:00:00 2001 From: JoseluCross Date: Thu, 30 Jun 2016 13:07:35 +0200 Subject: [PATCH] Error correction ("), improve error control (~ to $HOME) --- jka-toolkit/gitdit | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/jka-toolkit/gitdit b/jka-toolkit/gitdit index 1b80a97..dca66f3 100755 --- a/jka-toolkit/gitdit +++ b/jka-toolkit/gitdit @@ -2,11 +2,11 @@ # gitdit, a dialog interface to manage git repositories # Author: JKA Network - contacto@jkanetwork.com -VERSION="0.2.3" +VERSION="0.3.0" #First check if the user is in a git repository preOption=$(git status 2>/dev/stdout | sed -n 1p | cut -f2 -d" ") if [ $preOption = "Not" ];then #When it isn't only it can do git clone - gitopt=`dialog --stdout --scrollbar --menu "gitdit - Git DIalog inTerface" 0 0 6 c "Descargar un nuevo repo (Hacer clone)"" i "Inicializar nuevo repo"` + gitopt=`dialog --stdout --scrollbar --menu "gitdit - Git DIalog inTerface" 0 0 6 c "Descargar un nuevo repo (Hacer clone)" i "Inicializar nuevo repo"` else #Else, all other options gitopt=`dialog --stdout --scrollbar --menu "gitdit - Git DIalog inTerface" 0 0 6 p "Descargar actualizaciones del git (Hacer pull)" t "Confirmar cambios sin subida" s "Subir actualizaciones al git (Hacer push)" n "Crear nueva rama" b "Cambiar de branch/rama (Hacer checkout)" m "Unir ramas (Hacer merge)"` actual="origin $(git branch --list | grep "^*" | cut -f2 -d" ")" #Current branch @@ -15,7 +15,24 @@ if [ ! -z $gitopt ];then #No canceled case $gitopt in #Not staying in a git repo "i") - git init + gitdir=`dialog --stdout --inputbox "Directorio del repositorio" 10 60 "."` + if [ $(echo $gitdir | cut -f1 -d"/") = "~" ];then #~ don't understand like $HOME + cant=$(echo $gitdir | grep -o "/" | wc -l) + gitdirdef="$HOME" + for (( i=2; 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 "No tienes permiso para escribir en ese directorio" >> /dev/stderr + else + cd $gitdirdef + git init + fi ;; "c") giturl=`dialog --stdout --inputbox "URL del git" 10 60` @@ -29,7 +46,7 @@ if [ ! -z $gitopt ];then #No canceled "p") git pull $actual;; "s") - estado=$(git status | grep "^Changes" ) #It need to commit something? + estado=$(git status | grep -o "^Changes" ) #It need to commit something? if [ $estado ];then #When is necesary commit commit=`dialog --stdout --inputbox "Cambios (texto commit)" 10 50 "changes"` if [[ -z $commit ]];then