Skip to contentSkip to conversation

dim: handle missing declare -n option gracefully

PATCH New Jani Nikula 1 participant 2 messages Jan 31, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 dim: handle missing declare -n option gracefully

The declare -n option was added in bash 4.3. Handle missing -n gracefully, at the expense of losing dim alias functionality.

---
 dim | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
dim +3 -3
index 9500a9df102a..20eac8c58c58 100755
@@ -1598,9 +1598,9 @@ function dim_usage
 	echo "See '$dim help' for more information."
 }
 
-# dim subcommand aliases
-declare -n subcmd=dim_alias_${subcommand//-/_}
-if [ -z "$subcmd" ]; then
+# dim subcommand aliases (with bash 4.3+)
+if ! declare -n subcmd=dim_alias_${subcommand//-/_} &> /dev/null || \
+		test -z "$subcmd"; then
 	subcmd="$subcommand"
 fi
 
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 2/2 dim: document how to define subcommand aliases

---
 dim.rst | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
dim.rst +10 -1
index 97b375e34e90..911b4666b4aa 100644
@@ -330,9 +330,10 @@ Run the given command in all active workdirs including the main repository under
 
 list-aliases
 ------------
-
 List all aliases for the subcommand names. Useful for autocompletion scripts.
 
+See \$dim_alias_<alias> under ENVIRONMENT below on how to define aliases.
+
 list-branches
 -------------
 
@@ -401,6 +402,14 @@ DIM_TEMPLATE_SIGNATURE
 ----------------------
 Path to a file containing a signature template for pull request mails.
 
+dim_alias_<alias>
+-----------------
+Make **<alias>** an alias for the subcommand defined as the value. For example,
+`dim_alias_ub=update-branches`. There are some built-in aliases. Aliases can be
+listed using the **list-aliases** subcommand.
+
+The alias functionality requires **bash(1)** version 4.3 or later to work.
+
 CONTRIBUTING
 ============
 
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx