2015-04-16 9 views
6

Birisi bu bash işlevini balığa dönüştürmeme yardımcı olabilir mi? Bu önceden "${@%%.app}”, 's/ /.*/g’, "[email protected]\” vbBash işlevini balığa dönüştürme

bid() { 
    local shortname location 

    # combine all args as regex 
    # (and remove ".app" from the end if it exists due to autocomplete) 
    shortname=$(echo "${@%%.app}"|sed 's/ /.*/g') 
    # if the file is a full match in apps folder, roll with it 
    if [ -d "/Applications/$shortname.app" ]; then 
     location="/Applications/$shortname.app" 
    else # otherwise, start searching 
     location=$(mdfind -onlyin /Applications -onlyin ~/Applications -onlyin /Developer/Applications 'kMDItemKind==Application'|awk -F '/' -v re="$shortname" 'tolower($NF) ~ re {print $0}'|head -n1) 
    fi 
    # No results? Die. 
    [[ -z $location || $location = "" ]] && echo "$1 not found, I quit" && return 
    # Otherwise, find the bundleid using spotlight metadata 
    bundleid=$(mdls -name kMDItemCFBundleIdentifier -r "$location") 
    # return the result or an error message 
    [[ -z $bundleid || $bundleid = "" ]] && echo "Error getting bundle ID for \"[email protected]\"" || echo "$location: $bundleid” 
} 

Çok teşekkürler seversin açıklamak durumunda da güzel olurdu.farklara

+2

nasıl kendi başınıza bu sorunu çözmek için çalıştı? – mcserep

cevap

16

bazı notlar:

  • ayar değişkenleri
    • bash: var=value
    • balık: set var value
  • fonksiyon argümanları
  • işlevi yerel değişkenler
    • bash: local var
    • balık: set -l var
  • şart ben
    • bash: [[ ... ]] ve [ ... ]
    • balık: test ...
  • koşul II
    • Bash: if cond; then cmds; fi
    • balık: if cond; cmds; end
  • koşul III
    • Bash: cmd1 && cmd2
    • balık: cmd1; and cmd2
  • komut ikamesi
    • Bash: output=$(pipeline)
    • balık: set output (pipeline)
  • işlem ikame
    • Bash: join <(sort file1) <(sort file2)
    • balık: join (sort file1 | psub) (sort file2 | psub)

Belgeler

+0

Yine de "$ {@ %%. App}" adlı balık eşdeğerini anlayamıyorum. Ne yaptığını biliyorum, en sonunda .app içeren tüm $ stringi döndür. Bu yüzden balıkta '$ argv [**. App]' olacağını düşünürdüm, ama 'Exp' genişletme hatası veriyor. – user14492

+0

'$ {@ %%. App}', kaldırılan tüm ".app" uzantılı tüm konumsal parametrelerin bir listesini döndürür. Balık eşdeğeri, argv için arg'dir; set args $ args (echo "$ arg" | sed 's/.app $ //'); –

+0

Sanırım yukarıdaki yorumda $ ile birlikte "sed’/.app $ // ‘" bir yazım hatası yapmış olabilirsiniz. Aksi halde neden orada olduğunu açıklayabilir misiniz? Argv dizisinin her öğesi için – user14492