From da4104da8d2d4c7bb51259ae45ee546b4f30850b Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sun, 31 Mar 2013 22:22:56 +0000 Subject: [PATCH] fixed up the ssh_agent fixer. updated some of the debian stuff. --- .debian | 17 +----- .exports | 8 +-- .functions | 154 +++++++++++++++++++++++++------------------------ .gitmodules | 5 +- setup.sh | 2 - ssh-find-agent | 1 - 6 files changed, 85 insertions(+), 102 deletions(-) delete mode 160000 ssh-find-agent diff --git a/.debian b/.debian index d294a1ec..51031397 100644 --- a/.debian +++ b/.debian @@ -1,16 +1,5 @@ -sudo -v -INSTALL="apt-get -y install" +INSTALL="sudo apt-get -y install" $INSTALL zsh $INSTALL tmux -$INSTALL emacs -$INSTALL nmap -$INSTALL readline - -# python dependencies -$INSTALL libreadline5-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev -cd ~/Downloads -wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz -tar -xvf Python-2.7.2.tgz && cd Python-2.7.2/ -./configure -make -sudo make altinstall \ No newline at end of file +$INSTALL emacs24-nox +$INSTALL nmap \ No newline at end of file diff --git a/.exports b/.exports index f74718c7..88ebec14 100644 --- a/.exports +++ b/.exports @@ -21,10 +21,4 @@ export LESS_TERMCAP_md="$ORANGE" export MANPAGER="less -X" git config --global user.name "Ivan Malison" -git config --global user.email IvanMalison@gmail.com - -# EC2 stuff. -export JAVA_HOME="$(/usr/libexec/java_home)" -export EC2_PRIVATE_KEY="$(/bin/ls "$HOME"/.ec2/pk-*.pem | /usr/bin/head -1)" -export EC2_CERT="$(/bin/ls "$HOME"/.ec2/cert-*.pem | /usr/bin/head -1)" -export EC2_HOME="/usr/local/Library/LinkedKegs/ec2-api-tools/jars" \ No newline at end of file +git config --global user.email IvanMalison@gmail.com \ No newline at end of file diff --git a/.functions b/.functions index eab7f664..db7e92df 100644 --- a/.functions +++ b/.functions @@ -1,136 +1,142 @@ -source ~/ssh-find-agent/ssh-find-agent.bash +find_all_ssh_agent_sockets() { + find /tmp -type s -name agent.\* 2> /dev/null | grep '/tmp/ssh-.*/agent.*' +} + +set_ssh_agent_socket() { + export SSH_AUTH_SOCK=$(find_all_ssh_agent_sockets | tail -n 1 | awk -F: '{print $1}') +} # Simple calculator function calc() { - local result="" - result="$(printf "scale=10;$*\n" | bc --mathlib | tr -d '\\\n')" + local result="" + result="$(printf "scale=10;$*\n" | bc --mathlib | tr -d '\\\n')" # └─ default (when `--mathlib` is used) is 20 # - if [[ "$result" == *.* ]]; then + if [[ "$result" == *.* ]]; then # improve the output for decimal numbers - printf "$result" | - sed -e 's/^\./0./' `# add "0" for cases like ".5"` \ - -e 's/^-\./-0./' `# add "0" for cases like "-.5"`\ + printf "$result" | + sed -e 's/^\./0./' `# add "0" for cases like ".5"` \ + -e 's/^-\./-0./' `# add "0" for cases like "-.5"`\ -e 's/0*$//;s/\.$//' # remove trailing zeros - else - printf "$result" - fi - printf "\n" + else + printf "$result" + fi + printf "\n" } # Create a new directory and enter it function mkd() { - mkdir -p "$@" && cd "$@" + mkdir -p "$@" && cd "$@" } # Determine size of a file or total size of a directory function fs() { - if du -b /dev/null > /dev/null 2>&1; then - local arg=-sbh - else - local arg=-sh - fi - if [[ -n "$@" ]]; then - du $arg -- "$@" - else - du $arg .[^.]* * - fi + if du -b /dev/null > /dev/null 2>&1; then + local arg=-sbh + else + local arg=-sh + fi + if [[ -n "$@" ]]; then + du $arg -- "$@" + else + du $arg .[^.]* * + fi } # Use Git’s colored diff when available hash git &>/dev/null if [ $? -eq 0 ]; then - function diff() { - git diff --no-index --color-words "$@" - } + function diff() { + git diff --no-index --color-words "$@" + } fi # Create a data URL from a file function dataurl() { - local mimeType=$(file -b --mime-type "$1") - if [[ $mimeType == text/* ]]; then - mimeType="${mimeType};charset=utf-8" - fi - echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')" + local mimeType=$(file -b --mime-type "$1") + if [[ $mimeType == text/* ]]; then + mimeType="${mimeType};charset=utf-8" + fi + echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')" } # Start an HTTP server from a directory, optionally specifying the port function server() { - local port="${1:-8000}" - sleep 1 && open "http://localhost:${port}/" & + local port="${1:-8000}" + sleep 1 && open "http://localhost:${port}/" & # Set the default Content-Type to `text/plain` instead of `application/octet-stream` # And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files) - python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port" + python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port" } # Start a PHP server from a directory, optionally specifying the port # (Requires PHP 5.4.0+.) function phpserver() { - local port="${1:-4000}" - local ip=$(ipconfig getifaddr en1) - sleep 1 && open "http://${ip}:${port}/" & - php -S "${ip}:${port}" + local port="${1:-4000}" + local ip=$(ipconfig getifaddr en1) + sleep 1 && open "http://${ip}:${port}/" & + php -S "${ip}:${port}" } # Compare original and gzipped file size function gz() { - local origsize=$(wc -c < "$1") - local gzipsize=$(gzip -c "$1" | wc -c) - local ratio=$(echo "$gzipsize * 100/ $origsize" | bc -l) - printf "orig: %d bytes\n" "$origsize" - printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio" + local origsize=$(wc -c < "$1") + local gzipsize=$(gzip -c "$1" | wc -c) + local ratio=$(echo "$gzipsize * 100/ $origsize" | bc -l) + printf "orig: %d bytes\n" "$origsize" + printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio" } # Test if HTTP compression (RFC 2616 + SDCH) is enabled for a given URL. # Send a fake UA string for sites that sniff it instead of using the Accept-Encoding header. (Looking at you, ajax.googleapis.com!) function httpcompression() { - encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding" + encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding" } # Syntax-highlight JSON strings or files # Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json` function json() { - if [ -t 0 ]; then # argument - python -mjson.tool <<< "$*" | pygmentize -l javascript - else # pipe - python -mjson.tool | pygmentize -l javascript - fi + if [ -t 0 ]; then # argument + python -mjson.tool <<< "$*" | pygmentize -l javascript + else # pipe + python -mjson.tool | pygmentize -l javascript + fi } # All the dig info function digga() { - dig +nocmd "$1" any +multiline +noall +answer + dig +nocmd "$1" any +multiline +noall +answer } # Escape UTF-8 characters into their 3-byte format function escape() { - printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u) - echo # newline + printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u) + echo # newline } # Decode \x{ABCD}-style Unicode escape sequences function unidecode() { - perl -e "binmode(STDOUT, ':utf8'); print \"$@\"" - echo # newline + perl -e "binmode(STDOUT, ':utf8'); print \"$@\"" + echo # newline } # Get a character’s Unicode code point function codepoint() { - perl -e "use utf8; print sprintf('U+%04X', ord(\"$@\"))" - echo # newline + perl -e "use utf8; print sprintf('U+%04X', ord(\"$@\"))" + echo # newline } # Add note to Notes.app (OS X 10.8) # Usage: `note 'foo'` or `echo 'foo' | note` function note() { - local text - if [ -t 0 ]; then # argument - text="$1" - else # pipe - text=$(cat) - fi - body=$(echo "$text" | sed -E 's|$|
|g') - osascript >/dev/null <|g') + osascript >/dev/null </dev/null </dev/null <