├── History.md ├── Readme.md ├── package.json ├── wifi-password.plugin.zsh └── wifi-password.sh /History.md: -------------------------------------------------------------------------------- 1 | 2 | 0.1.0 / 2015-02-14 3 | ================== 4 | 5 | * default to `quiet` when piping (non-tty) 6 | 7 | 0.0.1 / 2015-02-14 8 | ================== 9 | 10 | * initial release 11 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # wifi-password 3 | 4 | People ask you for the Wi-Fi password. Answer quickly. **macOS only**. 5 | [Windows version](https://github.com/RReverser/WiFi-Password). 6 | 7 | ![](https://i.cloudup.com/uUo8iSbKXRh/km6iJT.gif) 8 | 9 | ## How to use 10 | 11 | **1. Install it** 12 | 13 | With [bpkg](https://github.com/bpkg/bpkg): 14 | 15 | ``` 16 | $ bpkg install rauchg/wifi-password 17 | ``` 18 | 19 | With [Homebrew](https://github.com/Homebrew/homebrew): 20 | 21 | ``` 22 | $ brew install wifi-password 23 | ``` 24 | 25 | With [Antigen](https://github.com/zsh-users/antigen): 26 | 27 | Add `antigen bundle rauchg/wifi-password` to your `.zshrc` with your other antigen commands 28 | 29 | With [Zgen](https://github.com/tarjoilija/zgen) 30 | 31 | Add `zgen load rauchg/wifi-password` to your `.zshrc` with your other zgen commands 32 | 33 | or with `curl`: 34 | 35 | ``` 36 | curl -L https://raw.github.com/rauchg/wifi-password/master/wifi-password.sh -o ~/bin/wifi-password && chmod +x ~/bin/wifi-password 37 | ``` 38 | 39 | If you don't have `~/bin` in your `$PATH`, replace it with `/usr/local/bin` or 40 | similar. 41 | 42 | **2. Use it:** 43 | 44 | To get the password for the WiFi you're currently logged onto: 45 | 46 | ``` 47 | $ wifi-password 48 | ``` 49 | 50 | To get it for a specific SSID: 51 | 52 | ``` 53 | $ wifi-password 54 | ``` 55 | 56 | To put it straight in your clipboard for pasting elsewhere (OS X only): 57 | 58 | ``` 59 | $ wifi-password | pbcopy 60 | ``` 61 | 62 | ## License 63 | 64 | MIT 65 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wifi-password", 3 | "version": "0.1.0", 4 | "description": "People ask you for the Wi-Fi password. Answer quickly.", 5 | "global": "1", 6 | "install": "install -b wifi-password.sh ${PREFIX:-/usr/local}/bin/wifi-password", 7 | "scripts": [ "wifi-password.sh" ] 8 | } 9 | 10 | -------------------------------------------------------------------------------- /wifi-password.plugin.zsh: -------------------------------------------------------------------------------- 1 | # This plugin is MIT licensed. 2 | # 3 | # Make git-open easy to install and keep up to date if you're using a 4 | # ZSH framework like Zgen or Antigen 5 | 6 | export PATH=$(dirname $0):${PATH} 7 | -------------------------------------------------------------------------------- /wifi-password.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | version="0.1.0" 4 | 5 | # locate airport(1) 6 | airport="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport" 7 | if [ ! -f $airport ]; then 8 | echo "ERROR: Can't find \`airport\` CLI program at \"$airport\"." 9 | exit 1 10 | fi 11 | 12 | # by default we are verbose (unless non-tty) 13 | if [ -t 1 ]; then 14 | verbose=1 15 | else 16 | verbose= 17 | fi 18 | 19 | # usage info 20 | usage() { 21 | cat <&2 64 | exit 1 65 | fi 66 | fi 67 | 68 | # warn user about keychain dialog 69 | if [ $verbose ]; then 70 | echo "" 71 | echo "\033[90m … getting password for \"$ssid\". \033[39m" 72 | echo "\033[90m … keychain prompt incoming. \033[39m" 73 | fi 74 | 75 | sleep 2 76 | 77 | # source: http://blog.macromates.com/2006/keychain-access-from-shell/ 78 | pwd="`security find-generic-password -D 'AirPort network password' -ga \"$ssid\" 2>&1 >/dev/null`" 79 | 80 | if [[ $pwd =~ "could" ]]; then 81 | echo "ERROR: Could not find SSID \"$ssid\"" >&2 82 | exit 1 83 | fi 84 | 85 | # clean up password 86 | pwd=$(echo "$pwd" | sed -e "s/^.*\"\(.*\)\".*$/\1/") 87 | 88 | if [ "" == "$pwd" ]; then 89 | echo "ERROR: Could not get password. Did you enter your Keychain credentials?" >&2 90 | exit 1 91 | fi 92 | 93 | # print 94 | if [ $verbose ]; then 95 | echo "\033[96m ✓ \"$pwd\" \033[39m" 96 | echo "" 97 | else 98 | echo $pwd 99 | fi 100 | --------------------------------------------------------------------------------