commit 2929bc51611b8e93aad23140352c608d8c0c38e6 parent 3e4b9ad237a5db21d863736695c70724d114ec14 Author: Alex Balgavy <a.balgavy@gmail.com> Date: Mon, 4 Jun 2018 14:35:21 +0200 Rearranged commonprofile Diffstat:
M | commonprofile | | | 30 | ++++++++++++++++++------------ |
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/commonprofile b/commonprofile @@ -20,7 +20,6 @@ cd() { builtin cd -P "$@"; ls; } # List contents mkcd() { mkdir -p -- "$1" && cd -P -- "$1" } # Make dir and cd at the same time procinfo() { ps -aux | grep $1 } # Get info about a process (by name) rmempty() { find ${1-.} -type d -empty -depth -delete } # Remove empty directories -fsel() { osascript -e 'tell application "Finder" to return POSIX path of (first item of (get selection as alias list) as alias)' | rev | sed 's/^\///' | rev; } batterypct() { ioreg -l | awk '$3~/Capacity/{c[$3]=$5}END{OFMT="%.2f%%";max=c["\"MaxCapacity\""];print(max>0?100*c["\"CurrentCapacity\""]/max:"?")}' | sed 's/\..*//'; } ### DOUG SCRIPTS TRIAL RESET ### @@ -100,18 +99,25 @@ current_wifi_password() { security find-generic-password -ga "$1" | grep password } -cdf() { - target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'` - if [ "$target" != "" ]; then - cd "$target"; pwd - else - echo 'No Finder window found' >&2 - fi -} -gdf() { - echo `osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'` -} +### MAC FINDER-SPECIFIC ### +if command -v osascript &> /dev/null; then + cdf() { + target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'` + if [ "$target" != "" ]; then + cd "$target"; pwd + else + echo 'No Finder window found' >&2 + fi + } + gdf() { + echo `osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'` + } + fsel() { + osascript -e 'tell application "Finder" to return POSIX path of (first item of (get selection as alias list) as alias)' | rev | sed 's/^\///' | rev; + }; +fi +# This is still a bit buggy realpath() { if [ $# -eq 1 ]; then if [ -e $1 ]; then