]> git.nbdom.net Git - nb.git/commitdiff
shell functions
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 8 Jul 2015 15:05:52 +0000 (16:05 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 8 Jul 2015 15:05:52 +0000 (16:05 +0100)
etc/bashrc.function
etc/profile.d/darwin.sh

index 86167de60daba3becf07e16b32fb83c97d6f83fa..ae4b4967523d1a1c385005d15181d8fae6888ff8 100644 (file)
@@ -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"'
 }
index 82e379dca818184d9e288dd11cb725067197cea1..ac6fbbfcc4ddc378d645225b6a8f459e44963563 100644 (file)
@@ -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"