Skip to content

Commit

Permalink
Support four new file managers as first beta release
Browse files Browse the repository at this point in the history
  • Loading branch information
damonlynch committed Sep 9, 2021
1 parent 94913ab commit 354201f
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 23 deletions.
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
Changelog for Show in File Manager
==================================

0.0.8 (2012-08-31)
0.9.0 (2021-09-08)
------------------
- Add option to specify file manager to use from command line
- Support [Double Commander](https://doublecmd.sourceforge.io/)
- Support [Krusader](https://krusader.org/)
- Support [SpaceFM](https://ignorantguru.github.io/spacefm/)
- Support [fman](https://fman.io/)

0.0.8 (2021-08-31)
------------------
- Support [CutefishOS](https://en.cutefishos.com/).
- Support [Index File Manager](https://invent.kde.org/maui/index-fm).
Expand All @@ -12,12 +20,10 @@ Changelog for Show in File Manager

0.0.6 (2021-08-19)
------------------

- Remove get_ prefix from package level function names.

0.0.5 (2021-08-19)
------------------

- Add setup.py for man page generation.
- Improve README to clarify installation and usage.
- Parse filename globs passed via the command line on Windows.
Expand All @@ -43,5 +49,4 @@ Changelog for Show in File Manager

0.0.1 (2021-08-12)
------------------

- Initial release.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Although this package provides several functions to assist in identifying the th
circumstances you need to call only one function, the function `show_in_file_manager`, and it should just work.

This package aspires to be platform independent, but it currently supports only Windows 10/11, Linux, WSL, and macOS. It
works with 14 [supported file managers](#supported-file-managers).
works with 18 [supported file managers](#supported-file-managers).


## How to install and run
Expand Down Expand Up @@ -78,11 +78,11 @@ WSL — this package will launch `explorer.exe` using the command line under

## Supported file managers

All file managers tested thus far accept [URIs](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier) like
`file:///home/user/file.txt`, as well as regular paths like `/home/user/file.txt`.

This package takes care of calling the file managers with the correct arguments for you. The command line arguments
shown here are for reference:
shown here are for reference.

Almost all file managers accept [URIs](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)
like `file:///home/user/file.txt` in addition to regular paths like `/home/user/file.txt`.

|File Manager|Used by|Command line |Can Select Files|Handles Multiple Files / Directories|Notes|
|------------|-------|-------------------|:---:|:---:|----|
Expand All @@ -99,7 +99,12 @@ shown here are for reference:
|PCManFM|LXDE|`pcmanfm URI`|❌|❌|Specifying a file opens it. Multiple URIs open only the first URI.|
|[PCManFM-Qt](https://github.com/lxqt/pcmanfm-qt)|LXQt|`pcmanfm-qt URI1 URI2`|❌|⚠|Specifying a file opens it. Multiple URIs open multiple PCManFM-Qt windows.|
|[CutefishOS File Manager](https://github.com/cutefishos/filemanager)|CutefishOS|`cutefish-filemanager`|❌|❌|Specifying a file causes File Manager to attempt to open it as if it is a folder. Multiple URIs open only the first URI.|
|[Index](https://invent.kde.org/maui/index-fm)| |`index URI1 URI2` |❌|❌|Specifying a file has no effect. Multiple URIs open multiple tabs, in addition to the user's home directory, which is always opened.|
|[Index](https://invent.kde.org/maui/index-fm)|Linux|`index URI1 URI2` |❌|❌|Specifying a file has no effect. Multiple URIs open multiple tabs, in addition to the user's home directory, which is always opened.|
|[Double Commander](https://doublecmd.sourceforge.io/)|Windows, Linux|`doublecmd URI1 URI2`|✅|⚠|A double panel file manager accepting up to two URIs. Cannot select folders.|
|[Krusader](https://krusader.org/)|KDE|`krusader URI`|❌|⚠|A double panel file manager accepting one URI. Two URIs can be specified using `--left` and `--right`, but that is unsupported by this package. Specifying a file causes an error.|
|[SpaceFM](https://ignorantguru.github.io/spacefm/)|Linux|`spacefm URI1 URI2`|❌|✅|Specifying a file opens it.|
|[fman](https://fman.io/)|Windows, Linux, macOS|`fman path1 path2`|✅|⚠|A double panel file manager accepting up to two paths. Cannot select folders. Does not accept URIs.|


## Usage

Expand Down
6 changes: 6 additions & 0 deletions doc/showinfilemanager.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ directory the file is found in.
**--version**
: Show program's version number and exit.

**-f**, **--file-manager** **FILE_MANAGER**
: File manager to run

**-s**, **--select-folder**
: Select folder instead of displaying its contents. By default, when a URI or path is a directory and
not a file, the directory itself is shown in the file manager. This option changes the default and
Expand All @@ -43,6 +46,9 @@ directory the file is found in.
**showinfilemanager ~/myfile.txt**
: Open the system file manager and select *~/myfile.txt* in the user's home directory.

**showinfilemanager -f dolphin \*.txt**
: Open the dolphin file manager and select all the files with extension *txt* in the current directory.

**showinfilemanager D:\\Documents\\\*.docx**
: Open the system file manager and select all the Word documents in the Documents directory on the D: drive.

Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = show-in-file-manager
version = 0.0.8
version = 0.9.0
author = Damon Lynch
author_email = [email protected]
description = Open the system file manager and select files in it
Expand All @@ -19,7 +19,7 @@ classifiers =
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows :: Windows 10
Operating System :: POSIX :: Linux
Development Status :: 3 - Alpha
Development Status :: 4 - Beta
Topic :: Desktop Environment :: File Managers
[options]
package_dir =
Expand Down
4 changes: 3 additions & 1 deletion src/showinfm/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FileManagerType(Enum):
show_items = 5 # file_manager --show-items
win_select = 6 # explorer.exe /select
reveal = 7 # open --reveal (macOS)
dual_panel = 8 # file_manager "File1" "File2"


class Platform(Enum):
Expand All @@ -20,4 +21,5 @@ class Platform(Enum):
macos = 3


single_file_only = ('explorer.exe', 'pcmanfm', 'open', 'cutefish-filemanager')
single_file_only = ('explorer.exe', 'pcmanfm', 'open', 'cutefish-filemanager')
cannot_open_uris = ('fman', 'fman.exe')
25 changes: 15 additions & 10 deletions src/showinfm/showinfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import urllib.parse


from .constants import FileManagerType, Platform, single_file_only
from .constants import FileManagerType, Platform, single_file_only, cannot_open_uris
from .system import current_platform, is_wsl
from .system import linux, tools, windows

Expand Down Expand Up @@ -187,15 +187,15 @@ def show_in_file_manager(path_or_uri: Optional[Union[str, Sequence[str]]] = None
# Were we passed a URI or simple path?
if pu:
if tools.is_uri(pu):
if current_platform == Platform.windows:
if current_platform == Platform.windows or file_manager in cannot_open_uris:
# Convert URI to regular path
uri = None
path = Path(tools.file_url_to_path(pu))
else:
uri = pu
path = None
else:
if current_platform == Platform.windows:
if current_platform == Platform.windows or file_manager in cannot_open_uris:
# Do not convert the path to a URI, as that can mess things up on WSL
path = Path(pu)
uri = None
Expand All @@ -221,11 +221,11 @@ def show_in_file_manager(path_or_uri: Optional[Union[str, Sequence[str]]] = None
uri = urllib.parse.urlunparse(parse_result._replace(path=str(path)))
else:
path = tools.quote_path(path)

uris_and_paths.append(uri or path)
uris_and_paths.append(uri or str(path))
else:
open_directory = False
if open_not_select_directory or file_manager_type == FileManagerType.regular:
if open_not_select_directory and file_manager_type != FileManagerType.dual_panel \
or file_manager_type == FileManagerType.regular:
if uri:
parse_result = urllib.parse.urlparse(uri)
path = Path(parse_result.path)
Expand All @@ -246,7 +246,7 @@ def show_in_file_manager(path_or_uri: Optional[Union[str, Sequence[str]]] = None
path = tools.quote_path(path)
directories.append(uri or str(path))
if not open_directory:
if uri is None and (is_wsl or current_platform != Platform.windows):
if uri is None and (is_wsl or file_manager != "explorer.exe"):
path = tools.quote_path(path)
uris_and_paths.append(uri or str(path))

Expand All @@ -262,7 +262,7 @@ def show_in_file_manager(path_or_uri: Optional[Union[str, Sequence[str]]] = None
elif file_manager_type == FileManagerType.reveal:
arg = '--reveal ' # trailing space is necessary

if current_platform == Platform.windows and not is_wsl:
if current_platform == Platform.windows and not is_wsl and file_manager == 'explorer.exe':
if uris_and_paths:
windows.launch_file_explorer(uris_and_paths, verbose)
for d in directories:
Expand Down Expand Up @@ -317,7 +317,7 @@ def _file_manager_type(fm: str) -> FileManagerType:
"""

if current_platform == Platform.windows:
return FileManagerType.win_select
return windows.windows_file_manager_type(fm)
elif current_platform == Platform.linux:
return linux.linux_file_manager_type(fm)
elif current_platform == Platform.macos:
Expand Down Expand Up @@ -418,6 +418,10 @@ def parser_options(formatter_class=argparse.HelpFormatter):
'--version', action='version', version='%(prog)s {}'.format(version)
)

parser.add_argument(
'-f', '--file-manager', help="file manager to run"
)

parser.add_argument(
'-s', '--select-folder', action='store_true', help="select folder instead of displaying its contents"
)
Expand Down Expand Up @@ -450,7 +454,8 @@ def main() -> None:

try:
show_in_file_manager(
path_or_uri=path_or_uri, verbose=verbose, open_not_select_directory=open_not_select_directory
file_manager=args.file_manager, path_or_uri=path_or_uri, verbose=verbose,
open_not_select_directory=open_not_select_directory
)
except Exception as e:
sys.stderr.write(str(e))
Expand Down
4 changes: 4 additions & 0 deletions src/showinfm/system/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ class LinuxDesktop(Enum):
pcmanfm=FileManagerType.dir_only_uri,
peony=FileManagerType.show_items,
index=FileManagerType.dir_only_uri,
doublecmd=FileManagerType.dual_panel,
krusader=FileManagerType.dir_only_uri,
spacefm=FileManagerType.dir_only_uri,
fman=FileManagerType.dual_panel,
)
LinuxFileManagerBehavior['pcmanfm-qt'] = FileManagerType.dir_only_uri
LinuxFileManagerBehavior['dde-file-manager'] = FileManagerType.show_item
Expand Down
18 changes: 18 additions & 0 deletions src/showinfm/system/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@
pass

from .tools import is_uri, path_to_file_url, file_url_to_path, directories_and_their_files
from ..constants import FileManagerType


WindowsFileManagerBehavior = {}
WindowsFileManagerBehavior['doublecmd.exe'] = FileManagerType.dual_panel
WindowsFileManagerBehavior['fman.exe'] = FileManagerType.dual_panel


def windows_file_manager_type(file_manager: str) -> FileManagerType:
"""
Determine the type of command line arguments the Windows file manager expects
:param file_manager: executable name
:return: FileManagerType matching with the executable name, else FileManagerType.regular as a fallback
"""

if file_manager == 'explorer.exe':
return FileManagerType.win_select
return WindowsFileManagerBehavior.get(file_manager, FileManagerType.regular)


def parse_command_line_arguments(path_or_uri: List[str]) -> List[str]:
Expand Down

0 comments on commit 354201f

Please sign in to comment.