From 39f54c28050a924670d631b3fa6d05c04d6d49e8 Mon Sep 17 00:00:00 2001 From: Felix Sonntag Date: Mon, 19 Jan 2015 23:27:48 +0100 Subject: [PATCH] osx plugin: Updated description implementation, improved argument checking --- .../{OSX-README.markdown => README.markdown} | 0 plugins/osx/cdf.fish | 9 +----- plugins/osx/itunes.fish | 7 ++--- plugins/osx/manp.fish | 9 +----- plugins/osx/pfd.fish | 9 +----- plugins/osx/pfs.fish | 9 +----- plugins/osx/pushdf.fish | 9 +----- plugins/osx/ql.fish | 13 +++----- plugins/osx/tab.fish | 9 +----- plugins/osx/trash.fish | 31 +++++++++---------- 10 files changed, 26 insertions(+), 79 deletions(-) rename plugins/osx/{OSX-README.markdown => README.markdown} (100%) diff --git a/plugins/osx/OSX-README.markdown b/plugins/osx/README.markdown similarity index 100% rename from plugins/osx/OSX-README.markdown rename to plugins/osx/README.markdown diff --git a/plugins/osx/cdf.fish b/plugins/osx/cdf.fish index fc0d80a..ec4a8b7 100644 --- a/plugins/osx/cdf.fish +++ b/plugins/osx/cdf.fish @@ -1,12 +1,5 @@ # cd to the current Finder directory -function cdf - if count $argv >/dev/null - switch $argv[1] - case -d --description - echo "cd to the current Finder directory" - return 0 - end - end +function cdf -d "cd to the current Finder directory" cd (pfd) end \ No newline at end of file diff --git a/plugins/osx/itunes.fish b/plugins/osx/itunes.fish index 2262b14..139197c 100644 --- a/plugins/osx/itunes.fish +++ b/plugins/osx/itunes.fish @@ -1,12 +1,9 @@ # Play, pause etc. iTunes -function itunes - if count $argv >/dev/null +function itunes -d "Play, pause etc. iTunes. Use -h or --help for a more detailed description." + if [ (count $argv) -gt 0 ] set -l opt $argv[1] switch $opt - case -d --description - echo "Play, pause etc. iTunes. Use -h or --help for a more detailed description." - return 0 case launch play pause stop rewind resume quit case mute set opt "set mute to true" diff --git a/plugins/osx/manp.fish b/plugins/osx/manp.fish index 37c3289..3899cbb 100644 --- a/plugins/osx/manp.fish +++ b/plugins/osx/manp.fish @@ -1,12 +1,5 @@ # Open a specified man page in Preview -function manp - if count $argv >/dev/null - switch $argv[1] - case -d --description - echo "Open a specified man page in Preview" - return 0 - end - end +function manp -d "Open a specified man page in Preview" man -t $argv | open -f -a Preview end \ No newline at end of file diff --git a/plugins/osx/pfd.fish b/plugins/osx/pfd.fish index 7ddb5f2..974ca7c 100644 --- a/plugins/osx/pfd.fish +++ b/plugins/osx/pfd.fish @@ -1,13 +1,6 @@ # Return the path of the frontmost Finder window -function pfd - if count $argv >/dev/null - switch $argv[1] - case -d --description - echo "Return the path of the frontmost Finder window" - return 0 - end - end +function pfd -d "Return the path of the frontmost Finder window" osascript 2>/dev/null -e ' tell application "Finder" return POSIX path of (target of window 1 as alias) diff --git a/plugins/osx/pfs.fish b/plugins/osx/pfs.fish index f7f9a51..31022e0 100644 --- a/plugins/osx/pfs.fish +++ b/plugins/osx/pfs.fish @@ -1,13 +1,6 @@ # Return the path of the frontmost Finder window -function pfs - if count $argv >/dev/null - switch $argv[1] - case -d --description - echo "Return the path of the frontmost Finder window" - return 0 - end - end +function pfs -d "Return the path of the frontmost Finder window" osascript 2>/dev/null -e ' set output to "" tell application "Finder" to set the_selection to selection diff --git a/plugins/osx/pushdf.fish b/plugins/osx/pushdf.fish index 2e6f8a8..ec81f6f 100644 --- a/plugins/osx/pushdf.fish +++ b/plugins/osx/pushdf.fish @@ -1,12 +1,5 @@ # pushd to the current Finder directory -function pushdf - if count $argv >/dev/null - switch $argv[1] - case -d --description - echo "pushd to the current Finder directory" - return 0 - end - end +function pushdf -d "pushd to the current Finder directory" pushd (pfd) end \ No newline at end of file diff --git a/plugins/osx/ql.fish b/plugins/osx/ql.fish index 85c3164..fa52c4f 100644 --- a/plugins/osx/ql.fish +++ b/plugins/osx/ql.fish @@ -1,14 +1,9 @@ # Quick Look a specified file -function ql - if count $argv >/dev/null - switch $argv[1] - case -d --description - echo "Quick Look a specified file" - return 0 - end - end - if count $argv > 0 +function ql -d "Quick Look a specified file" + if [ (count $argv) -gt 0 ] qlmanage >/dev/null ^/dev/null -p Applications/ & + else + echo "No file or folder as argument given" end end \ No newline at end of file diff --git a/plugins/osx/tab.fish b/plugins/osx/tab.fish index ceda6af..0b73e4a 100644 --- a/plugins/osx/tab.fish +++ b/plugins/osx/tab.fish @@ -1,12 +1,5 @@ # Open the current directory in a new tab -function tab - if count $argv >/dev/null - switch $argv[1] - case -d --description - echo "Open the current directory in a new tab" - return 0 - end - end +function tab -d "Open the current directory in a new tab" osascript 2>/dev/null -e ' tell application "System Events" tell process "Terminal" to keystroke "t" using command down diff --git a/plugins/osx/trash.fish b/plugins/osx/trash.fish index 19a49a7..bf13a03 100644 --- a/plugins/osx/trash.fish +++ b/plugins/osx/trash.fish @@ -1,23 +1,20 @@ # Move a specified file to the Trash -function trash - if count $argv >/dev/null - switch $argv[1] - case -d --description - echo "Move a specified file to the Trash" - return 0 - end - end - set -l trash_dir "$HOME/.Trash" - for item in $argv - if test -e $item - set -l item_name (basename $item) - if test -e "$trash_dir/$item_name" - set -l current_time (date "+%H.%M.%S") - mv -f "$item" "$trash_dir/$item_name $current_time" - else - mv -f "$item" "$trash_dir/" +function trash -d "Move a specified file to the Trash" + if [ (count $argv) -gt 0 ] + set -l trash_dir "$HOME/.Trash" + for item in $argv + if test -e $item + set -l item_name (basename $item) + if test -e "$trash_dir/$item_name" + set -l current_time (date "+%H.%M.%S") + mv -f "$item" "$trash_dir/$item_name $current_time" + else + mv -f "$item" "$trash_dir/" + end end end + else + echo "No file(s) given to delete" end end \ No newline at end of file