From a8c08e2587f386b63d123cd8fef87c4a2f3d272c Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 8 Jul 2015 16:05:52 +0100 Subject: [PATCH] shell functions --- etc/bashrc.function | 31 +++++++++++++++++++++++++++++++ etc/profile.d/darwin.sh | 7 +++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/etc/bashrc.function b/etc/bashrc.function index 86167de6..ae4b4967 100644 --- a/etc/bashrc.function +++ b/etc/bashrc.function @@ -3,6 +3,37 @@ # FUNCTIONS - SH # ################################################################################# +shell_help() { + # + # Print help message and return true if args contains -?-h(elp)? + # + local msg="$1"; shift + + case "$@" in + *-h*|*-help*|*--help*) + case $OSTYPE in + darwin*) printf "$msg\n" ;; + *) echo -e "$msg" ;; + esac + return 0 + ;; + *) return 1 ;; + esac + +} + +shell_help_noarg() { + # + # Print help message and return true if args contains -?-h(elp)? or is empty + # + local msg="$1"; shift + + local args=""; args="$@" # zsh compatible + [ -z "$args" ] && args="--help" + + sem_help "$msg" "$args" +} + shell_functions() { set | perl -ne '/^([a-z][\w_-]+) \(\)\s*$/ and print "$1\n"' } diff --git a/etc/profile.d/darwin.sh b/etc/profile.d/darwin.sh index 82e379dc..ac6fbbfc 100644 --- a/etc/profile.d/darwin.sh +++ b/etc/profile.d/darwin.sh @@ -1,14 +1,17 @@ +mac_pbcopy() { + cat $@ | ssh -q $1 -o 'ForwardAgent yes' 'cat|pbcopy' +} [ -z "$DARWIN" ] && return 0 md5sum() { md5 $@ | sed "s/^MD5 (\(.*\)) = \(.*\)$/\2 \1/" } -mac-xmessage() { +mac_xmessage() { osascript -e "tell app \"System Events\" to display dialog \"$@\"" } -mac-config() { +mac_config() { echo "Finder path : YES" defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES echo "Finder quit : YES" -- 2.47.3