diff options
author | P. J. McDermott <pj@pehjota.net> | 2016-02-14 21:46:40 (EST) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2016-02-14 21:46:40 (EST) |
commit | 5da1775daf87fe38d46dcdeef6ed64c6fac0bd29 (patch) | |
tree | 0389b995add0684e7c8f0099d810dc3a7fb7ce0c /libsh/alias.sh | |
download | eggshell-5da1775daf87fe38d46dcdeef6ed64c6fac0bd29.zip eggshell-5da1775daf87fe38d46dcdeef6ed64c6fac0bd29.tar.gz eggshell-5da1775daf87fe38d46dcdeef6ed64c6fac0bd29.tar.bz2 |
Initial commit
Diffstat (limited to 'libsh/alias.sh')
-rw-r--r-- | libsh/alias.sh | 56 |
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}; }" +} |