Skip to content

Instantly share code, notes, and snippets.

@jameswebb68
Created January 3, 2014 19:31
Show Gist options
  • Save jameswebb68/8244825 to your computer and use it in GitHub Desktop.
Save jameswebb68/8244825 to your computer and use it in GitHub Desktop.
function to open explorer window for current working directory, provided absolute path, provided relative path, from within a cygwin ex: open (opens current working directory in an explorer window), open /home (opens home directory), open ../home
# open explorer directory relative, absolute or empty for current path
open() {
local var="$1"
[[ -z "$var" ]] && cygstart -x "$(cygpath -wa "$PWD")"
if [[ "${var:0:1}" == "/" ]]; then
[[ -d "$var" ]] || { echo "bad path"; return 1; }
cygstart -x "$(cygpath -wa "$var")"
elif [[ "${var:0:3}" == "../" ]]; then
[[ -d "$(cd "$var" 2>/dev/null && pwd)" ]] || { echo "bad path"; return 1; }
cygstart -x "$(cygpath -wa "$(cd "$var"; pwd)")"
else
[[ -d "${PWD}/${var}" ]] || { echo "bad path"; return 1; }
cygstart -x "$(cygpath -wa "${PWD}/${var}")"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment