diff --git a/.bashrc b/.bashrc index e8891b4..155af67 100644 --- a/.bashrc +++ b/.bashrc @@ -172,14 +172,14 @@ __read_ssh_agents() { # Read all the known ssh agent sockets into an array. # Returns: 0 = Processed and read the agents file without issue. # 1 = Error processing/reading the agents file. - local ERR FD I SOCK + local ERR I SOCK [[ ! -e "$HOME/.ssh/agents" ]] && touch "$HOME/.ssh/agents" # Lock the ~/.ssh/agents file. if [[ "$PLATFORM" == "Linux" ]]; then # Linux has 'flock', thankfully. - exec {FD}<"$HOME/.ssh/agents" && flock -E 10 -e -w 0.5 "$FD" + exec 9<"$HOME/.ssh/agents" && flock -E 10 -e -w 0.5 9 ERR=$? if (( ERR == 10 )); then printf "\\033[1;31m%s\\033[39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2 @@ -196,7 +196,6 @@ __read_ssh_agents() { for ((I = 0; I <= 5; I++)); do if shlock -p "$$" -f "$HOME/.ssh/agents.lock"; then exec 9<"$HOME/.ssh/agents" - FD="9" # Make note of the mtime for use in write_ssh_agents. SSH_AGENTS_MTIME="$(stat -f %Fm "$HOME/.ssh/agents")" ERR=0 @@ -216,13 +215,13 @@ __read_ssh_agents() { fi # Read the socket list (bash v2+ compliant) - while read -u "$FD" -r SOCK; do + while read -u 9 -r SOCK; do [[ -n "$SOCK" ]] && SSH_AUTH_SOCKS+=("$SOCK") done ERR=$? # Close the file descriptor (which on Linux releases the flock too). - : "$FD"<&- + exec 9<&- # On Darwin, release the lock on the file. rm -f "$HOME/.ssh/agents.lock" @@ -244,7 +243,7 @@ __write_ssh_agents() { # Returns: 0 = Processed and wrote the agents file without issue. # 1 = Error processing/writing the agents file. # 2 = The SSH_AUTH_SOCKS array may be out of date as the agents file'a mtime has changed. - local FD ERR I J MTIME SOCKS + local ERR I J MTIME SOCKS # Add the current agent socket to the sockets array. SSH_AUTH_SOCKS=("$SSH_AUTH_SOCK" "${SSH_AUTH_SOCKS[@]}") @@ -267,7 +266,7 @@ __write_ssh_agents() { (( ${MTIME/\.} > SSH_AGENTS_MTIME )) && return 2 # Lock the agents file. - exec {FD}>"$HOME/.ssh/agents" && flock -E 10 -e -w 0.5 "$FD" + exec 9<"$HOME/.ssh/agents" && flock -E 10 -e -w 0.5 9 ERR=$? if (( ERR == 10 )); then printf "\\033[1;31m%s\\033[39m\\n" "Failed to obtain lock on ~/.ssh/agents." >&2 @@ -284,8 +283,7 @@ __write_ssh_agents() { # Do locking the sucky way on OSX. for ((I = 0; I <= 5; I++)); do if shlock -p "$$" -f "$HOME/.ssh/agents.lock"; then - exec 9>"$HOME/.ssh/agents" - FD="9" + exec 9<"$HOME/.ssh/agents" ERR=0 break else @@ -307,7 +305,7 @@ __write_ssh_agents() { [[ -n "${SOCKS[*]}" ]] && { printf "%s\\n" "${SOCKS[@]}" >"$HOME/.ssh/agents" 2>/dev/null; ERR=$?; } # Release locks. - : "$FD"<&- + exec 9<&- rm -f "$HOME/.ssh/agents.lock" # Error out if the data couldn't be written. @@ -368,6 +366,9 @@ imagebin() { curl -F file="@$1" https://imagebin.ca/upload.php | grep '^url:' | cut -d: -f2- } +# Determine the platform being logged into. +PLATFORM="$(uname -s)" + # Make bash a little more pleasent - these are valid for all versions. shopt -s cdspell checkhash checkwinsize cmdhist histappend no_empty_cmd_completion @@ -451,9 +452,6 @@ hash ssh ssh-add >/dev/null 2>&1 && ssh() { command "${_EXEC:-${FUNCNAME[0]}}" "$@" } -# Determine the platform being logged into. -PLATFORM="$(uname -s)" - # Platform specific set up. if [[ "$PLATFORM" = "Linux" ]]; then # Linux specific functions.