]> git.nbdom.net Git - nb.git/commitdiff
functions
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Tue, 6 Sep 2016 14:57:40 +0000 (15:57 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Tue, 6 Sep 2016 14:57:40 +0000 (15:57 +0100)
bin/nb-update
etc/profile.d/functions
etc/profile.d/git.sh

index 870225f986c5131f9f9ca967a364fe7e70a2b03f..271aa4e222f39b2609af917c34b150695d67fa37 100755 (executable)
@@ -16,56 +16,9 @@ declare CLEANUP=0
 #####################################################################
 # Git Connection check
 #
-url2nc() {
-  perl -e '
-for (@ARGV) {
-@_ = m,://([^/:]+)(?::(\d+))?, and print join(" ",$_[0],$_[1] ? $_[1] : (/^https/?443:80))."\n", and next;
-@_ = m,^(?:[^@]+@)?([^:/]+):[^/].*?(?:\.git)?$, and print "$1 22\n" and next;
-@_ = m,([^@:/]+):[^/].*?(?:\.git)?$, and print "$1 22\n" and next;
-}
-' $@
-  return 0
-}
 #[ "$1" = "TEST" ] && url2nc nico@zaza.com:re.git && exit
 #[ "$1" = "TEST" ] && url2nc zaza.com:re.git && exit
 #[ "$1" = "TEST" ] && url2nc https://zaza.com/re.git && exit
-_git_conn_check=" "
-git_conn_check() {
-  #local dest=$(git config --local --get remote.origin.url | sed -e 's/:.*$//' -e 's/^.*@//')
-  local dest=$(git config --local --get remote.origin.url)
-  local port=''
-
-  if [ -z "$dest" ]; then
-    logger -t $NAME -s "Can't get url from \`git config --het remote.origin.url\` in `pwd`"
-    return 1
-  fi
-  #[ "$1" = "TEST" ] &&
-  dest=$(url2nc "$dest")
-  #dest="$dest 22"
-
-  local ok
-  case "$_git_conn_check" in
-    *" $dest=0 "*) ok=0 ;;
-    *" $dest=1 "*) ok=1 ;;
-    *)
-      ok=0
-      case "$dest" in
-        *"@"*) timeout 5 ssh -o BatchMode=yes -o ConnectTimeout=5 $dest true && ok=1 ;;
-        *) nc -z -w 5 $dest && ok=1 ;;
-      esac
-#echo "$ok: git=$(git config --local --get remote.origin.url) | dest=$dest | url2nc="$(url2nc $(git config --local --get remote.origin.url))
-      _git_conn_check="${_git_conn_check}$dest=$ok "
-    ;;
-  esac
-
-  #if ! timeout 5 ssh BatchMode=yes -o ConnectTimeout=5 $dest true; then
-  if [ "$ok" != "1" ]; then
-    logger -t $NAME -s "Can't connect to $dest"
-    return 1
-  fi
-
-  return 0
-}
 #cd $NB_ROOT || exit
 #git_conn_check || git_conn_check || exit
 #exec echo BYE
index aaf5ac8254d1d5253dd10a1606f19f281381f3b1..d11f3e03db722700c7a6bfc54310bcf721256a4c 100644 (file)
@@ -576,3 +576,9 @@ is_prompt() {
   [[ $- == *i* ]] && return 0
   return 1
 }
+
+url2nc() {
+  local in="cat";
+  [ -n "$@" ] && in="echo $@";
+  $in | perl -MURI::Split -ne 'BEGIN{%port=("ssh"=>22,"https"=>443,"http"=>80);}; chomp($_); m,^\w+://, or $_="ssh://$_"; s,:([a-zAZ]),/$1,; @_=URI::Split::uri_split($_) or next; $_=$_[1]; s/^[^@]+@//; s/:/ / or $_.=" ".$port{$_[0]||"ssh"}; print "$_\n"'
+}
index bfe513958e7a2df96c013a290ba453fb895ec714..f6f8f16274e0b72fc2660ec4e31835dc8eb8d709 100644 (file)
@@ -1,7 +1,7 @@
 #--------------------------------------------------------------------------------
 # Git
 #
-GIT_REPO='git@git.nbdom.net'
+[ -z "GIT_REPO" ] && GIT_REPO='git@git.nbdom.net'
 
 alias git_grep="git grep --color=auto"
 alias git_ls_tree="git ls-tree --full-tree -r HEAD"
@@ -121,3 +121,41 @@ git_list() {
   local repo=$(echo "$GIT_REPO" | perl -pe 's,^\w+://,,; s,/.*$,,;')
   ssh $repo list | perl -ne '/(\S+).git/ and print "$1\n"'
 }
+
+_git_conn_check=" "
+git_conn_check() {
+  #local dest=$(git config --local --get remote.origin.url | sed -e 's/:.*$//' -e 's/^.*@//')
+  local dest=$(git config --local --get remote.origin.url)
+  local port=''
+
+  if [ -z "$dest" ]; then
+    logger -t $NAME -s "Can't get url from \`git config --het remote.origin.url\` in `pwd`"
+    return 1
+  fi
+  #[ "$1" = "TEST" ] &&
+  dest=$(url2nc "$dest")
+  #dest="$dest 22"
+
+  local ok
+  case "$_git_conn_check" in
+    *" $dest=0 "*) ok=0 ;;
+    *" $dest=1 "*) ok=1 ;;
+    *)
+      ok=0
+      case "$dest" in
+        *"@"*) timeout 5 ssh -o BatchMode=yes -o ConnectTimeout=5 $dest true && ok=1 ;;
+        *) nc -z -w 5 $dest && ok=1 ;;
+      esac
+#echo "$ok: git=$(git config --local --get remote.origin.url) | dest=$dest | url2nc="$(url2nc $(git config --local --get remote.origin.url))
+      _git_conn_check="${_git_conn_check}$dest=$ok "
+    ;;
+  esac
+
+  #if ! timeout 5 ssh BatchMode=yes -o ConnectTimeout=5 $dest true; then
+  if [ "$ok" != "1" ]; then
+    logger -t $NAME -s "Can't connect to $dest"
+    return 1
+  fi
+
+  return 0
+}