From 5172ecf855078938b00e9ac7f8dee2c2676f6e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Tue, 13 Jan 2015 23:35:48 +0100 Subject: Commit initial --- cmdtemp | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 cmdtemp (limited to 'cmdtemp') diff --git a/cmdtemp b/cmdtemp new file mode 100755 index 0000000..37bcc82 --- /dev/null +++ b/cmdtemp @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# The MIT License (MIT) +# +# Copyright (c) 2011-2015 Ismaƫl Bouya http://www.normalesup.org/~bouya/ +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# cmdtemp +# List commands +# cmdtemp +# Execute command number +# cmdtemp <-n> +# Delete command number +# cmdtemp <...> +# Save command + + +function is_negative() { + s=$(echo $1 | tr -d 0-9) + if [ "$s" == "-" ]; then + return 0 + else + return 1 + fi +} + +function is_integer() { + s=$(echo $1 | tr -d 0-9) + if [ -z "$s" ]; then + return 0 + else + return 1 + fi +} + +if [ $# -eq 0 ]; then + cat -n $HOME/.cmdtemp + exit +fi + +if is_integer "$1"; then + ligne="$1" + shift + commande=`awk "FNR == $ligne" $HOME/.cmdtemp` + echo "*** "$commande + eval $commande +elif is_negative "$1"; then + s=$(echo $1 | tr -d '-') + sed -i -e $s"d" $HOME/.cmdtemp +else + echo "$*" >> $HOME/.cmdtemp +fi -- cgit v1.2.3