├── functions └── ql.fish ├── README.md ├── LICENSE └── osx-aliases.plugin.zsh /functions/ql.fish: -------------------------------------------------------------------------------- 1 | function ql 2 | qlmanage -p $argv > /dev/null ^ /dev/null& 3 | end 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | plugin-osx 2 | ========== 3 | 4 | Collection of OS X related functions for use with [fish] & [zsh] 5 | 6 | ## install 7 | 8 | ``` 9 | dotstrap install mkwmms/plugin-osx 10 | ``` 11 | 12 | see: [dotstrap] 13 | 14 | ## functions 15 | 16 | #### ql ([fish] only at the moment) 17 | 18 | OSX's quick look on the command line. Just opens a preview for whatever, escape closes it. 19 | 20 | ``` 21 | $ ql img.png 22 | ``` 23 | 24 | ## acknowledgements 25 | [brigand/fish-functions](https://github.com/brigand/fish-functions) 26 | 27 | [zsh]: http://zsh.sourceforge.net 28 | [fish]: http://fishshell.com/ 29 | [dotstrap]: https://github.com/mkwmms/dotstrap 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 william 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /osx-aliases.plugin.zsh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zsh 2 | 3 | if [[ "$OSTYPE" =~ ^(darwin)+ ]]; then 4 | info () { 5 | # shellcheck disable=SC2059 6 | printf "[ \033[00;34m...\033[0m ] $1\n" 7 | } 8 | 9 | user () { 10 | # shellcheck disable=SC2059 11 | printf "\r [ \033[0;33m?\033[0m ] $1 " 12 | } 13 | 14 | success () { 15 | # shellcheck disable=SC2059 16 | printf "\r\033[2K [ \033[00;32mOK\033[0m ] $1\n" 17 | } 18 | 19 | error () { 20 | # shellcheck disable=SC2059 21 | printf "\r\033[2K [ \033[0;31mERROR\033[0m ] $1\n" 22 | echo '' 23 | } 24 | 25 | # Get OS X Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages 26 | installed() { 27 | command -v "${1}" >/dev/null 2>&1 && info "${1}" || return false 28 | } 29 | 30 | # TODO: verify the error output works correctly... 31 | update() { 32 | if [[ "$1" == "-osx" ]]; then 33 | # Keep-alive: update existing `sudo` time stamp until `update` has finished 34 | sudo -v && while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & 35 | info "OS X Packages" && sudo softwareupdate -i -a || error "Updating OS X packages" 36 | fi 37 | 38 | installed "brew" && (brew update; brew upgrade --all; brew cleanup; brew cask cleanup;) && success "Updated brew" || error "Updating brew" 39 | installed "npm" && (npm install npm -g; npm update -g;) && success "Updated npm" || error "Updating npm" 40 | installed "gem" && (sudo gem update --system; sudo gem update) && success "Updated gem" || error "Updating gem" 41 | # upgrade outdated pip packages... 42 | installed "pip" && (pip install --upgrade pip && pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U) && success "Updated pip" || error "Updating pip" 43 | installed "pip3" && (pip3 install --upgrade pip && pip3 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U) && success "Updated pip3" || error "Updating pip3" 44 | } 45 | 46 | # IP addresses 47 | alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'" 48 | 49 | # Flush Directory Service cache 50 | alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder" 51 | 52 | # Clean up LaunchServices to remove duplicates in the “Open With” menu 53 | alias lscleanup="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder" 54 | 55 | # View HTTP traffic 56 | alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'" 57 | alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\"" 58 | 59 | # Canonical hex dump; some systems have this symlinked 60 | command -v hd > /dev/null || alias hd="hexdump -C" 61 | 62 | # OS X has no `md5sum`, so use `md5` as a fallback 63 | command -v md5sum > /dev/null || alias md5sum="md5" 64 | 65 | # OS X has no `sha1sum`, so use `shasum` as a fallback 66 | command -v sha1sum > /dev/null || alias sha1sum="shasum" 67 | 68 | # JavaScriptCore REPL 69 | jscbin="/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc"; 70 | [ -e "${jscbin}" ] && alias jsc="${jscbin}"; 71 | unset jscbin; 72 | 73 | # Trim new lines and copy to clipboard 74 | alias c="tr -d '\n' | pbcopy" 75 | 76 | # Empty the Trash on all mounted volumes and the main HDD 77 | # Also, clear Apple’s System Logs to improve shell startup speed 78 | alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl" 79 | 80 | # Show/hide hidden files in Finder 81 | alias show="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder" 82 | alias hide="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder" 83 | 84 | # Hide/show all desktop icons (useful when presenting) 85 | alias hidedesktop="defaults write com.apple.finder CreateDesktop -bool false && killall Finder" 86 | alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder" 87 | 88 | # URL-encode strings 89 | alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"' 90 | 91 | # Merge PDF files 92 | # Usage: `mergepdf -o output.pdf input{1,2,3}.pdf` 93 | alias mergepdf='/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py' 94 | 95 | # PlistBuddy alias, because sometimes `defaults` just doesn’t cut it 96 | alias plistbuddy="/usr/libexec/PlistBuddy" 97 | 98 | # Ring the terminal bell, and put a badge on Terminal.app’s Dock icon 99 | # (useful when executing time-consuming commands) 100 | alias badge="tput bel" 101 | 102 | # Intuitive map function 103 | # For example, to list all directories that contain a certain file: 104 | # find . -name .gitattributes | map dirname 105 | alias map="xargs -n1" 106 | 107 | # One of @janmoesen’s ProTip™s 108 | for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do 109 | alias "$method"="lwp-request -m '$method'" 110 | done 111 | 112 | # Stuff I never really use but cannot delete either because of http://xkcd.com/530/ 113 | alias stfu="osascript -e 'set volume output muted true'" 114 | alias pumpitup="osascript -e 'set volume 7'" 115 | 116 | # Diff 117 | alias gdiff='git diff --no-index --color-words ' 118 | alias diff2='diff -y --suppress-common-lines ' 119 | 120 | # turn ethernet on/off 121 | alias ethoff="sudo networksetup setnetworkserviceenabled 'Ethernet 1' off" 122 | alias ethon="sudo networksetup setnetworkserviceenabled 'Ethernet 1' on" 123 | 124 | trash() { 125 | if [[ "$1" =~ ^[-]?[aA]{1}(ll)*$ ]]; then 126 | sudo rm -rvf ~/Library/Logs/* 127 | sudo rm -rvf /Library/Logs/* 128 | sudo rm -rvf /var/log/* 129 | sudo rm -rfv /Volumes/*/.Trashes 130 | elif [[ "$1" =~ ^[-]?[uU]{1}(ser)*$ ]]; then 131 | rm -rvf ~/Library/Logs/* 132 | fi 133 | rm -rfv ~/.Trash/* 134 | rm -rfv ~/.Trash/.* 135 | } 136 | fi 137 | --------------------------------------------------------------------------------