diff --git a/Key Bindings.json b/Key Bindings.json new file mode 100644 index 0000000..ec2088b --- /dev/null +++ b/Key Bindings.json @@ -0,0 +1,3 @@ +[ + { "keys": ["Shift+u"], "command": "un_zip_selected" } +] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c064e0d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Thomas Haslwanter + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2f147aa --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +## UnZipSelected + +Plugin for [fman.io](https://fman.io) to unzip a file that has been selected in fman. + +Install with [fman's built-in command for installing plugins](https://fman.io/docs/installing-plugins). + +### Usage + +Select one file and press **Shift+u** + +### Features + + - Unzips the selected file into a directory with the same name as the current file name. diff --git a/unzipselected/__init__.py b/unzipselected/__init__.py new file mode 100644 index 0000000..13b2f0b --- /dev/null +++ b/unzipselected/__init__.py @@ -0,0 +1,25 @@ +from fman import DirectoryPaneCommand, show_alert +import os +import zipfile +from fman.url import as_human_readable +from fman.url import as_url + + +class UnZipSelected(DirectoryPaneCommand): + def __call__(self): + selected_files = self.pane.get_selected_files() + output = "" + if len(selected_files) >= 1 or (len(selected_files) == 0 and self.get_chosen_files()): + if len(selected_files) == 0 and self.get_chosen_files(): + selected_files.append(self.get_chosen_files()[0]) + dirPath = os.path.dirname(as_human_readable(selected_files[0])) + unZipName = os.path.basename(as_human_readable(selected_files[0])) + inFile = os.path.join(dirPath, unZipName) + unZipDir = unZipName[:-4] + unZipPath = os.path.join(dirPath, unZipDir) + zipfile.ZipFile(inFile).extractall(path=unZipPath) + output += "Files were unzipped to directory {0}".format(unZipDir) + else: + output += "No files or directories selected" + + show_alert(output)