From 26a977f44877d9dead5e1f6e0374b4501688e145 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Thu, 15 Aug 2019 21:58:08 +0300 Subject: [PATCH] Refactor: Use `$#` to check parameters --- .shellrc | 15 ++++++++------- bin/git-open | 5 ++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.shellrc b/.shellrc index 205f870..0677d0e 100644 --- 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 diff --git a/bin/git-open b/bin/git-open index da3561e..b25e8d9 100755 --- a/bin/git-open +++ b/bin/git-open @@ -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 -- 2.39.2