Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin for opening file browser from prompt #1039

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions plugins/open-window/open-window.plugin.zsh
@@ -0,0 +1,52 @@
############################################################################
# Open current directory in a file browser. Supports the following:
#
# * Explorer (Windows)
# * Explorer from Cygwin (Windows)
# * Finder (OS X)
# * Nautilus (Gnome)
# * Konqueror (KDE)
#
# Suggested use: bind open-current-window to a key so you can quickly
# pop open the current directory. I don't use backward-kill-word, so ^W
# works well for me:
#
# bindkey '^w' open-current-window
#
# The open-window function relies on OS-specific utilities that can open
# more than just a file browser. Capabilities vary from system to system,
# but most are designed to open the argument in whatever the system thinks
# is the best program for the job, usually by MIME type. URLs will also
# open in the default web browser.
#
# To use open-window on its own, your best bet is to alias it:
#
# alias o=open-window
############################################################################

open-window()
{
if (( $+commands[start] )) ; then
start $1
elif (( $+commands[cmd] )) ; then
# Cygwin can't directly run start from its bash prompt; use cmd shell
cmd /C start $1
elif (( $+commands[gnome-open] )) ; then
gnome-open $1
elif (( $+commands[kde-open] )) ; then
kde-open $1
elif (( $+commands[xdg-open] )) ; then
# Fallback that may or may not work on oddball Linux distros
xdg-open $1
elif (( $+commands[open] )); then
open $1
else
echo "No file browser found"
fi
}

open-current-window()
{
open-window .
}
zle -N open-current-window