]> git.phdru.name Git - dotfiles.git/commitdiff
Refactor: Use `$#` to check parameters
authorOleg Broytman <phd@phdru.name>
Thu, 15 Aug 2019 18:58:08 +0000 (21:58 +0300)
committerOleg Broytman <phd@phdru.name>
Thu, 15 Aug 2019 18:58:08 +0000 (21:58 +0300)
.shellrc
bin/git-open

index 205f870cb6d00d2b1de10f62eeda371cf74c7e74..0677d0e7f11407883a0552b386fb7dff5eeab0b8 100644 (file)
--- a/.shellrc
+++ b/.shellrc
@@ -188,13 +188,12 @@ chlo() { clear; cd; >$HISTFILE; unset HISTFILE; history -c; logout || exit; }
 if test -x /usr/bin/git >/dev/null 2>&1; then
    # chdir to a directory
    cdgitpath() {
-      if [ -z "$1" -o -n "$2" ]; then
+      if [ $# -ne 1 ]; then
          echo "Usage: cdgitpath path_key" >&2
          return 1
-      else
-         path_key="$1"
       fi
 
+      path_key="$1"
       if [ -z "$path_key" ]; then
          echo "Usage: cdgitpath path_key" >&2
          return 1
@@ -205,12 +204,14 @@ if test -x /usr/bin/git >/dev/null 2>&1; then
 
    # chdir to a remote's directory (if the remote is on the local FS)
    cdremote() {
+      if [ $# -gt 1 ]; then
+         echo "Usage: cdremote [remote_name]" >&2
+         return 1
+      fi
+
       if [ -z "$1" ]; then
          branch="`git rev-parse --abbrev-ref HEAD`"
          remote="`git config --get branch.$branch.remote`"
-      elif [ -n "$2" ]; then
-         echo "Usage: cdremote [remote_name]" >&2
-         return 1
       else
          remote="$1"
       fi
@@ -278,7 +279,7 @@ if test -x /usr/bin/git >/dev/null 2>&1; then
 
       # list remotes with URLs matching a regexp
       _list_remotes() {
-         if [ -z "$1" -o -n "$2" ]; then
+         if [ $#  -ne 1 ]; then
             echo "Usage: _list_remotes remote_regexp" >&2
             return 1
          fi
index da3561ebe52e041c81df8d5b8ba54387e0ec73a3..b25e8d9905de15a638a76c50e6160abdf161dfbe 100755 (executable)
@@ -1,12 +1,11 @@
 #! /bin/sh
 
-if [ -z "$1" -o -n "$2" ]; then
+if [ $# -ne 1 ]; then
    echo "Usage: git open url_key" >&2
    exit 1
-else
-   url_key="$1"
 fi
 
+url_key="$1"
 if [ -z "$url_key" ]; then
    echo "Usage: git open url_key" >&2
    exit 1