Skip to content

Commit

Permalink
Initial commit, unzip-plugin for fman
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Haslwanter committed Nov 28, 2018
0 parents commit 158bbc8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Key Bindings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{ "keys": ["Shift+u"], "command": "un_zip_selected" }
]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 25 additions & 0 deletions unzipselected/__init__.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 158bbc8

Please sign in to comment.