From: Nicolas Boisselier Date: Wed, 8 Jul 2015 13:26:48 +0000 (+0100) Subject: shell functions X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=e9271559dac82f6f725b2a43a88f73658a69a462;p=nb.git shell functions --- diff --git a/etc/bashrc b/etc/bashrc index 87fa72ba..4c3170f2 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -4,7 +4,7 @@ # ################################################################################# case "$BASH_SOURCE" in */*) path="${BASH_SOURCE%/*}";; *) path='.' ;; esac -. "$path/bashrc.function" +[ -e "$path/bashrc.function" ] && . "$path/bashrc.function" NB_ROOT=$(realpath ${path}/..) unset path diff --git a/etc/bashrc.function b/etc/bashrc.function index bc1eb0ab..86167de6 100644 --- a/etc/bashrc.function +++ b/etc/bashrc.function @@ -4,7 +4,24 @@ # ################################################################################# shell_functions() { - set | perl -ne '/^([\w_-]+) \(\)\s*$/ and print "$1\n"' + set | perl -ne '/^([a-z][\w_-]+) \(\)\s*$/ and print "$1\n"' +} + +shell_slogin() { + declare server; server="$1"; shift + declare tmp; tmp="/tmp/$FUNCNAME.$USER" + ( + alias + type $(shell_functions) | grep -v 'is a function$' + cat $NB_ROOT/etc/bashrc + ) | ssh "$server" "cat > $tmp || rm -vf $tmp" || return + + declare args + if [ -z "$@" ]; then + slogin -qt "$server" "bash --rcfile $tmp && rm -f $tmp" + else + slogin -qt "$server" "bash && rm -f $tmp" <<< ". $tmp; $@" + fi } ips() {