summaryrefslogtreecommitdiffstats
path: root/libsh/alias.sh
diff options
context:
space:
mode:
Diffstat (limited to 'libsh/alias.sh')
-rw-r--r--libsh/alias.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/libsh/alias.sh b/libsh/alias.sh
new file mode 100644
index 0000000..2945910
--- /dev/null
+++ b/libsh/alias.sh
@@ -0,0 +1,56 @@
+# Copyright (C) 2016 Patrick "P. J." McDermott
+#
+# This file is part of libsh.
+#
+# libsh is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# libsh is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with libsh. If not, see
+# <http://www.gnu.org/licenses/>.
+
+static check_args()
+{
+ local params="${1}"
+ shift 1
+ local p=
+
+ IFS=' '
+ for p in ${params}; do
+ unset IFS
+ if ! [ ${#} -gt 0 ]; then
+ return 1
+ fi
+ case "${p}" in
+ 'string')
+ ;;
+ 'int')
+ case "${1}" in *[!0-9]*) return 1;; esac
+ ;;
+ esac
+ shift 1
+ done
+ unset IFS
+
+ if ! [ ${#} -eq 0 ]; then
+ return 1
+ fi
+
+ return 0
+}
+
+__alias()
+{
+ local fn="${1}"
+ local alias="${2}"
+ local params="${*}"
+
+ eval "${alias}() { ${check_args} \"\${params}\" \"\${@}\" && ${fn}; }"
+}