Last active
July 19, 2022 16:52
-
-
Save luiscoms/aba9b843e2200697c778 to your computer and use it in GitHub Desktop.
My bash scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. "$HOME/.improvedbash/pretty-log.sh" | |
. "$HOME/.improvedbash/selfupdate.sh" -d | |
. "$HOME/.improvedbash/colors.sh" | |
. "$HOME/.improvedbash/ps1.sh" | |
# colorize bash commands | |
if uname -a | grep -qi linux; then | |
eval `dircolors -b` | |
alias ls='ls --color=auto' | |
alias l='ls -la --color' | |
alias grep='grep --color' | |
alias egrep='egrep --color' | |
alias mkcd='_(){ mkdir $1; cd $1; }; _' | |
alias vimdiff="vimdiff -c 'set diffopt+=iwhite'" | |
else | |
alias l='ls -la' | |
fi | |
export PATH=$PATH:$HOME/.improvedbash/ | |
# do not duplicate command history | |
export HISTCONTROL=ignoreboth |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins=(git chucknorris command-not-found docker docker-compose emoji-clock gcloud git safe-paste) | |
alias pbcopy='xclip -selection clipboard' | |
alias pbpaste='xclip -selection clipboard -o' | |
command -v gcloud && gcloud beta emulators pubsub env-init | |
#export GITLAB_PRIVATE_TOKEN= | |
[ -f $HOME/.cargo/env ] && . $HOME/.cargo/env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TXNC=`echo "\033[0m"` | |
TXNC='\e[m' | |
TXBLACK=`echo "\033[0;30m"` #Preto echo -e "${TXBLACK}Preto${TXNC}" | |
TXRED=`echo "\033[0;31m"` #Vermelho echo -e "${TXRED}Vermelho${TXNC}" | |
TXGREEN=`echo "\033[0;32m"` #Verde echo -e "${TXGREEN}Verde${TXNC}" | |
TXBROWN=`echo "\033[0;33m"` #Marron echo -e "${TXBROWN}Marrom${TXNC}" | |
TXBLUE=`echo "\033[0;34m"` #Azul echo -e "${TXBLUE}Azul${TXNC}" | |
TXPURPLE=`echo "\033[0;35m"` #Roxo echo -e "${TXPURPLE}Roxo${TXNC}" | |
TXCYAN=`echo "\033[0;36m"` #Ciano echo -e "${TXCYAN}Ciano${TXNC}" | |
TXLIGHTGRAY=`echo "\033[0;37m"` #Cinza Claro echo -e "${TXLIGHTGRAY}Cinza Claro${TXNC}" | |
TXDARKGRAY=`echo "\033[1;30m"` #Cinza Escuro echo -e "${TXDARKGRAY}Cinza Escuro${TXNC}" | |
TXLIGHTRED=`echo "\033[1;31m"` #Vermelho Claro echo -e "${TXLIGHTRED}Vermelho Claro${TXNC}" | |
TXLIGHTGREEN=`echo "\033[1;32m"` #Verde Claro echo -e "${TXLIGHTGREEN}Verde Claro${TXNC}" | |
TXYELLOW=`echo "\033[1;33m"` #Amarelo echo -e "${TXYELLOW}Amarelo${TXNC}" | |
TXYELLOW="\e[38;5;226m" | |
TXLIGHTBLUE=`echo "\033[1;34m"` #Azul Claro echo -e "${TXLIGHTBLUE}Azul Claro${TXNC}" | |
TXLIGHTBLUE="\e[38;5;111m" | |
TXLIGHTPURPLE=`echo "\033[1;35m"` #Rocho Claro echo -e "${TXLIGHTPURPLE}Rocho Claro${TXNC}" | |
TXLIGHTCYAN=`echo "\033[1;36m"` #Ciano Claro echo -e "${TXLIGHTCYAN}Ciano Claro${TXNC}" | |
TXWHITE=`echo "\033[1;37m"` #Branco echo -e "${TXWHITE}Branco${TXNC}" | |
TXWHITE='\e[1;37m' | |
# echo "Imprimindo cores" | |
# echo -e " \033[0;30m Preto \033[0m --> 0;30 " | |
# echo -e " \033[0;31m Vermelho \033[0m --> 0;31 " | |
# echo -e " \033[0;32m Verde \033[0m --> 0;32 " | |
# echo -e " \033[0;33m Marrom \033[0m --> 0;33 " | |
# echo -e " \033[0;34m Azul \033[0m --> 0;34 " | |
# echo -e " \033[0;35m Purple \033[0m --> 0;35 " | |
# echo -e " \033[0;36m Cyan \033[0m --> 0;36 " | |
# echo -e " \033[0;37m Cinza Claro \033[0m --> 0;37 " | |
# echo -e " \033[1;30m Preto Acinzentado \033[0m --> 1;30 " | |
# echo -e " \033[1;31m Vermelho Claro \033[0m --> 1;31 " | |
# echo -e " \033[1;32m Verde Claro \033[0m --> 1;32 " | |
# echo -e " \033[1;33m Amarelo \033[0m --> 1;33 " | |
# echo -e " \033[1;34m Azul Claro \033[0m --> 1;34 " | |
# echo -e " \033[1;35m Purple Claro \033[0m --> 1;35 " | |
# echo -e " \033[1;36m Cyan Claro \033[0m --> 1;36 " | |
# echo -e " \033[1;37m Branco \033[0m --> 1;37 " | |
# echo -e " \033[40;1;37m Fundo Preto \033[0m --> 40;?;? " | |
# echo -e " \033[41;1;37m Fundo Vermelho \033[0m --> 41;?;? " | |
# echo -e " \033[42;1;37m Fundo Verde \033[0m --> 42;?;? " | |
# echo -e " \033[43;1;37m Fundo Marrom \033[0m --> 43;?;? " | |
# echo -e " \033[44;1;37m Fundo Azul \033[0m --> 44;?;? " | |
# echo -e " \033[45;1;37m Fundo Purple \033[0m --> 45;?;? " | |
# echo -e " \033[46;1;37m Fundo Cyan \033[0m --> 46;?;? " | |
# echo -e " \033[47;1;37m Fundo Cinza \033[0m --> 47;?;? " | |
# echo -e " \033[4;30m Sublinhado \033[0m --> 4;? " | |
# echo -e " \033[5;30m Piscando \033[0m --> 5;? " | |
# echo -e " \033[7;30m Invertido \033[0m --> 7;? " | |
# echo -e " \033[8;30m Concealed \033[0m --> 8;? " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo -ne '\r[\e[38;5;196m########## \e[m] (33%) ' | |
sleep 0.4 | |
echo -ne '\r[\e[38;5;226m#################### \e[m] (66%) ' | |
sleep 0.4 | |
echo -ne '\r[\e[38;5;154m#############################\e[m] (100%)' | |
sleep 1 | |
echo -ne '\r \r' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOG_LEVEL_ERROR=1 | |
LOG_LEVEL_WARNING=2 | |
LOG_LEVEL_INFO=4 | |
LOG_LEVEL_DEBUG=8 | |
LOG_LEVEL_VERBOSE=16 | |
LOG_LEVEL_ALL=$(( $LOG_LEVEL_ERROR | $LOG_LEVEL_WARNING | $LOG_LEVEL_INFO | $LOG_LEVEL_INFO | $LOG_LEVEL_DEBUG | $LOG_LEVEL_VERBOSE )) | |
# LOG_LEVEL=$(($LOG_LEVEL_ALL ^ $LOG_LEVEL_VERBOSE)) | |
function print_log() { | |
local PREFIX="Log" | |
if ! [ -z $LOG_LEVEL ] && [ $(( ${LOG_LEVEL} & $LOG_LEVEL_DEBUG )) -eq $LOG_LEVEL_DEBUG ]; then | |
echo -e "[\e[38;5;172m$PREFIX\e[m] $*" | |
fi; | |
} | |
function print_info() { | |
local PREFIX=" i " | |
if ! [ -z $LOG_LEVEL ] && [ $(( ${LOG_LEVEL} & $LOG_LEVEL_INFO )) -eq $LOG_LEVEL_INFO ]; then | |
echo -e "[\e[38;5;45m$PREFIX\e[m] $*" | |
fi; | |
} | |
function print_checkpoint() { | |
local CHECKMARK="\xe2\x88\x9a" | |
if ! [ -z $LOG_LEVEL ] && [ $(( ${LOG_LEVEL} & $LOG_LEVEL_VERBOSE )) -eq $LOG_LEVEL_VERBOSE ]; then | |
echo -e "[ \e[38;5;10m$CHECKMARK\e[m ] \e[1;37m$*\e[m" | |
fi; | |
} | |
function print_warning() { | |
local PREFIX=" ! " | |
if ! [ -z $LOG_LEVEL ] && [ $(( ${LOG_LEVEL} & $LOG_LEVEL_WARNING )) -eq $LOG_LEVEL_WARNING ]; then | |
echo -e "[\e[38;5;227m$PREFIX\e[m] \e[1;37m$*\e[m" | |
fi; | |
} | |
function print_error() { | |
local CHECKMARK=" × " | |
if ! [ -z $LOG_LEVEL ] && [ $(( ${LOG_LEVEL} & $LOG_LEVEL_ERROR )) -eq $LOG_LEVEL_ERROR ]; then | |
echo -e "[ \e[38;5;196m$CHECKMARK\e[m ] \e[1;37m$*\e[m" | |
fi; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function print_currentCVSBranch() { | |
local NO_CHANGES_COLOR='\e[38;5;112m' | |
local COLOR_RESET='\e[m' | |
local final_color=$NO_CHANGES_COLOR | |
if [ "$PS1_COLORS" != "true" ];then | |
final_color='' | |
COLOR_RESET='' | |
fi | |
local branch_name=`if [ -f CVS/Entries ];then \ | |
cat CVS/Entries | grep "^/.\+\([^/]\+\)\(//.*\)$" | head -n1 | sed 's|\(.*\)\(//.*\)$|\2|' | sed 's|//$|HEAD|'; \ | |
fi` | |
if ! [ -z $branch_name ];then | |
echo -ne " $final_color($branch_name)$COLOR_RESET" | sed "s|\(//\)\?\w\?$1_\?||" # clean the branch name | |
fi | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function print_branch_color() { | |
local LOCAL_CHANGES_COLOR='\e[38;5;226m' | |
local UNTRACKED_CHANGES_COLOR='\e[38;5;196m' | |
local LOCAL_AND_UNTRACKED_CHANGES_COLOR='\e[38;5;214m' | |
local NO_CHANGES_COLOR='\e[38;5;112m' | |
local COMMITS_AHEAD_OR_BEHIND='\e[38;5;142m' | |
local COLOR_RESET='\e[m' | |
local branch_name=`git branch 2>/dev/null | grep -e '\*' --color=never | sed 's/[^ ]\s\([azAZ]*\)/\1/'` | |
local final_color="" | |
if [[ $branch_name =~ .+ ]]; then | |
#git fetch &>/dev/null | |
case "$(git status 2>/dev/null | grep -E -o 'nothing|Untracked|Changes|to be committed|Unmerged' | paste -s -d",")" in | |
"nothing") | |
#if $(git push -n origin master 2>&1 | grep up-to-date &>/dev/null); then | |
if [[ $(git status 2>/dev/null | grep -E "behind|ahead|diverged" 2>/dev/null) ]]; then | |
final_color="$COMMITS_AHEAD_OR_BEHIND" | |
else | |
final_color="$NO_CHANGES_COLOR" | |
fi | |
;; | |
'Untracked' | 'Untracked,nothing' | 'Unmerged' | 'Unmerged,Untracked') | |
final_color="$UNTRACKED_CHANGES_COLOR" | |
;; | |
'Changes,to be committed') | |
final_color="\e[38;5;228m" | |
;; | |
'Changes,Untracked') | |
final_color="$LOCAL_AND_UNTRACKED_CHANGES_COLOR" | |
;; | |
*) | |
final_color="$LOCAL_CHANGES_COLOR" | |
;; | |
esac | |
echo -ne "$final_color" | |
fi | |
} | |
function print_currentGitBranch() { | |
local LOCAL_CHANGES_COLOR='\e[38;5;226m' | |
local UNTRACKED_CHANGES_COLOR='\e[38;5;196m' | |
local LOCAL_AND_UNTRACKED_CHANGES_COLOR='\e[38;5;214m' | |
local NO_CHANGES_COLOR='\e[38;5;112m' | |
local COMMITS_AHEAD_OR_BEHIND='\e[38;5;142m' | |
local COLOR_RESET='\e[m' | |
local final_color='' | |
local branch_name=`git branch 2>/dev/null | grep -e '\*' --color=never | sed 's/[^ ]\s\([azAZ]*\)/\1/'` | |
local wrap=false | |
local timelineSymbol=false | |
if [[ $branch_name =~ .+ ]]; then | |
case "$(git status 2>/dev/null | grep -E -o 'nothing|Untracked|Changes|to be committed|Unmerged' | paste -s -d",")" in | |
"nothing") | |
#if $(git push -n origin master 2>&1 | grep up-to-date &>/dev/null); then | |
if [[ $(git status 2>/dev/null | grep -E "behind|ahead|diverged" 2>/dev/null) ]]; then | |
final_color="$COMMITS_AHEAD_OR_BEHIND" | |
else | |
final_color="$NO_CHANGES_COLOR" | |
fi | |
;; | |
'Untracked' | 'Untracked,nothing' | 'Unmerged' | 'Unmerged,Untracked') | |
final_color="$UNTRACKED_CHANGES_COLOR" | |
;; | |
'Changes,to be committed') | |
final_color="\e[38;5;228m" | |
;; | |
'Changes,Untracked') | |
final_color="$LOCAL_AND_UNTRACKED_CHANGES_COLOR" | |
;; | |
*) | |
final_color="$LOCAL_CHANGES_COLOR" | |
;; | |
esac | |
if [ "$PS1_COLORS" != "true" ];then | |
final_color='' | |
COLOR_RESET='' | |
fi | |
if [[ "$1" =~ \-.*w.*|\-\-wrap ]]; then | |
wrap=true; | |
fi | |
if [[ "$1" =~ \-.*t.*|\-\-wrap ]]; then | |
timelineSymbol=true; | |
fi | |
if $timelineSymbol; then | |
case "$(git status 2>/dev/null | grep -E -o 'behind|ahead|diverged' | paste -s -d",")" in | |
"behind") | |
timelineSymbol="--" | |
;; | |
"ahead") | |
timelineSymbol="++" | |
;; | |
"diverged") | |
timelineSymbol="><" | |
;; | |
*) | |
timelineSymbol="" | |
;; | |
esac | |
if [[ ! -z $timelineSymbol ]]; then | |
branch_name="$branch_name $timelineSymbol" | |
fi | |
fi | |
if $wrap; then | |
branch_name=" ($branch_name)" | |
fi | |
echo -ne "$final_color$branch_name$COLOR_RESET" | |
fi | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
. "$HOME/.improvedbash/ps1-git.sh" | |
. "$HOME/.improvedbash/ps1-cvs.sh" | |
function print_branch() { | |
print_currentGitBranch -wt | |
print_currentCVSBranch $1 | |
} | |
if [ -z "$PS1_SEPARETOR" ];then | |
PS1_SEPARETOR=" → " | |
PS1_SEPARETOR=" : " | |
fi | |
if [ -z "$PS1_HOSTCOLOR" ];then | |
PS1_HOSTCOLOR=$TXLIGHTBLUE | |
fi | |
if [ -z "$PS1_PATHCOLOR" ];then | |
PS1_PATHCOLOR=$TXWHITE | |
fi | |
# PS1="\[\e[38;5;111m\]\h\[\e[m\] → \[\e[1;37m\]\w\[\e[m\]\[\$(print_branch \W)\]\[\e[m\] \$ " | |
if [ "$PS1_COLORS" = "true" ];then | |
if [ "$PS1_MODIFY" = "true" ];then | |
PS1="\[${PS1_HOSTCOLOR}\]\h\[${TXNC}\]${PS1_SEPARETOR}\[${PS1_PATHCOLOR}\]\w\[${TXNC}\]\$(print_branch \W) \$ " # with colors | |
else | |
PS1="[\[${PS1_HOSTCOLOR}\]\u@\h\[${TXNC}\] \[${PS1_PATHCOLOR}\]\W\[${TXNC}\]\$(print_branch \W)]$ " # use default PS1 | |
fi | |
else | |
if [ "$PS1_MODIFY" = "true" ];then | |
PS1="\h${PS1_SEPARETOR}\w\$(print_branch \W) \$ " # No color | |
else | |
PS1="[\u@\h \W\$(print_branch \W)]$ " # use default PS1 | |
fi | |
fi | |
export PS1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
${PS1_DEFAULT_COLORS:="false"} | |
[ -z $PS1_DEFAULT_SEPARETOR ] && PS1_DEFAULT_SEPARETOR=" : " # if modify ps1 use this separetor | |
${PS1_DEFAULT_MODIFY:="false"} # modify the ps1 | |
BASHRC_FILE=$HOME/.bashrc | |
BIN_DIR=~/.improvedbash/ | |
BASHRC_DELIMITER="# Added by improvedbash" | |
GIST_USER=luiscoms | |
GIST_ID=aba9b843e2200697c778 | |
function downloadScripts() { | |
# Create bin dir | |
mkdir -p $BIN_DIR | |
# Download scripts | |
local ZIP_FILE=$(mktemp) | |
wget --no-check-certificate -O ${ZIP_FILE} https://gist.github.com/${GIST_USER}/${GIST_ID}/download; | |
# -i for junk paths | |
unzip -jo ${ZIP_FILE} -d $BIN_DIR | |
rm ${ZIP_FILE} | |
} | |
function cleanBashrcLegacy() { | |
local bin_dir=$HOME/bin | |
local delimiter="# Added by luiscoms" | |
local bashrc_lines="`grep -i \"# Added by luiscoms\" ${BASHRC_FILE} | wc -l`" | |
case "$bashrc_lines" in | |
"0") | |
# just add | |
;; | |
"1") | |
# delete lines first | |
# cat ${BASHRC_FILE} | grep -nA1 "${BASHRC_DELIMITER}" | sed 's|^\([0-9]\+\).*|\1|' | |
# exit | |
sed -i.bak "`cat ${BASHRC_FILE} | grep -nA1 \"${delimiter}\" | sed 's|^\([0-9]\+\).*|\1|' | paste -s -d','`d" ${BASHRC_FILE} | |
;; | |
*) | |
# delete lines first | |
sed -i.bak "`cat ${BASHRC_FILE} | grep -n \"${delimiter}\" | cut -d':' -f1 | paste -s -d','`d" ${BASHRC_FILE} | |
;; | |
esac | |
# remove old files | |
rm -f ${bin_dir}/{.bash_profile,colors.sh,load.sh,pretty-log.sh,ps1-cvs.sh,ps1-git.sh,ps1.sh,selfupdate.sh} | |
} | |
function cleanBashrc() { | |
cleanBashrcLegacy | |
local bashrc_lines="`grep -i \"${BASHRC_DELIMITER}\" ${BASHRC_FILE} | wc -l`" | |
case "$bashrc_lines" in | |
"0") | |
# just add | |
;; | |
"1") | |
# delete lines first | |
# cat ${BASHRC_FILE} | grep -nA1 "${BASHRC_DELIMITER}" | sed 's|^\([0-9]\+\).*|\1|' | |
# exit | |
sed -i.bak "`cat ${BASHRC_FILE} | grep -nA1 \"${BASHRC_DELIMITER}\" | sed 's|^\([0-9]\+\).*|\1|' | paste -s -d','`d" ${BASHRC_FILE} | |
;; | |
*) | |
# delete lines first | |
sed -i.bak "`cat ${BASHRC_FILE} | grep -n \"${BASHRC_DELIMITER}\" | cut -d':' -f1 | paste -s -d','`d" ${BASHRC_FILE} | |
;; | |
esac | |
# search again | |
print_log " matched $bashrc_lines lines" | |
local bashrc_lines="`grep -i \"${BASHRC_DELIMITER}\" ${BASHRC_FILE} | wc -l`" | |
print_log " returning $bashrc_lines" | |
if [ $bashrc_lines -eq "0" ]; then | |
if [ -z $GIST_LAST_UPDATED ]; then | |
local GIST_LAST_UPDATED=`wget "https://api.github.com/gists/${GIST_ID}" --no-check-certificate --quiet --timeout=2 -O - | grep -oP "updated_at\"\: \"(.+?)\"" | cut -d "\"" -f 3` | |
GIST_LAST_UPDATED=$(echo $GIST_LAST_UPDATED | sed 's/\(Z\|[+-][0-9]\+\)$//') | |
fi | |
local GIST_DOWNLOADED_AT="$(date -u -Iseconds | sed 's/\(Z\|[+-][0-9]\+\)$//')" | |
# just add | |
cat <<SCRIPT >> "$BASHRC_FILE" | |
${BASHRC_DELIMITER} | |
# set variables if unsetted | |
\${PS1_COLORS:="$PS1_DEFAULT_COLORS"} | |
[ -z \$PS1_SEPARETOR ] && PS1_SEPARETOR="$PS1_DEFAULT_SEPARETOR" # if modify ps1 use this separetor | |
\${PS1_MODIFY:="$PS1_DEFAULT_MODIFY"} # modify the ps1 | |
GIST_DOWNLOADED_AT="$GIST_DOWNLOADED_AT" | |
if [ -f ${BIN_DIR}.bash_profile ]; then | |
. ${BIN_DIR}.bash_profile | |
fi | |
${BASHRC_DELIMITER} | |
SCRIPT | |
fi | |
} | |
function selfUpdate() { | |
local invalid=true | |
read -p "Scripst was updated, do you want to update local scripts (y/n)?" choice | |
while [ $invalid = true ] | |
do | |
case "$choice" in | |
y|Y ) | |
print_log "${TXLIGHTGREEN}Yes${TXNC}" | |
downloadScripts | |
cleanBashrc | |
source $BASHRC_FILE | |
invalid=false | |
;; | |
n|N ) | |
print_log "${TXRED}No${TXNC}" | |
invalid=false | |
;; | |
* ) | |
#print_log -e "${TXRED}Invalid${TXNC}" | |
read -p "Please type 'y' or 'n': " choice | |
;; | |
esac | |
done | |
} | |
HELP_TEXT=\ | |
" USAGE:\n | |
selfupdate.sh [-d|--download|-c|--clean] \n | |
\t -c|--clean reset the bashrc file\n | |
\t -d|--download download the scripts\n | |
" | |
TEMP=`getopt -o dc --long download,clean \ | |
-n 'customise-bash.sh' -- "$@"` | |
if [ $? != 0 ] || (($# == 0)); then echo -e $HELP_TEXT >&2 ; exit 1 ; fi | |
# Note the quotes around `$TEMP': they are essential! | |
eval set -- "$TEMP" | |
downloadFlag="false" | |
cleanFlag="false" | |
while true ; do | |
case "$1" in | |
-d|--download) downloadFlag="true" ;; | |
-c|--clean) cleanFlag="true" ;; | |
# for options with required arguments, an additional shift is required | |
(--) shift; break;; | |
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;; | |
(*) break;; | |
esac | |
shift | |
done | |
#echo downloadFlag=${downloadFlag} | |
#echo cleanFlag=${cleanFlag} | |
if [ ${downloadFlag} = "true" ]; then | |
GIST_LAST_UPDATED=`wget "https://api.github.com/gists/${GIST_ID}" --no-check-certificate --quiet --timeout=2 -O - | grep -oP "updated_at\"\: \"(.+?)\"" | cut -d "\"" -f 3` | |
print_log "Last updated gist: "${GIST_LAST_UPDATED} | |
if ! [ -z $GIST_LAST_UPDATED ] && ! [ -z $GIST_DOWNLOADED_AT ]; then | |
# fix old bash | |
GIST_LAST_UPDATED=$(echo $GIST_LAST_UPDATED | sed 's/\(Z\|[+-][0-9]\+\)$//') | |
GIST_DOWNLOADED_AT=$(echo $GIST_DOWNLOADED_AT | sed 's/\(Z\|[+-][0-9]\+\)$//') | |
print_log "Testing if "$(date -u -Iseconds -d $GIST_LAST_UPDATED) $(date +%s -d $GIST_LAST_UPDATED) "is grater than " $(date -u -Iseconds -d $GIST_DOWNLOADED_AT) $(date +%s -d $GIST_DOWNLOADED_AT) | |
if [ $(date +%s -d $GIST_LAST_UPDATED) -gt $(date +%s -d $GIST_DOWNLOADED_AT) ]; then | |
selfUpdate | |
else | |
print_info "Gist is up to date" | |
fi; | |
fi; | |
fi; | |
[ ${cleanFlag} = "true" ] && cleanBashrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Luis. I have a problem in Git branch name with your last update. Can you see that? You can create a Github Repository for community contribute. Thanks.