Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions bin/easy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,7 @@ def add_editor_action():
mv = cfg_view # [global] the main view
mv.ai.start()
try:
lsp = "/launch_stash.py" # TODO: auto-detect
paa.add_action(
lsp,
"monitor",
"000000",
"StaSh",
)
paa.save_defaults()
_stash("pinstash -f")
finally:
mv.ai.stop()

Expand Down
90 changes: 90 additions & 0 deletions bin/pinstash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-
"""Create or update StaSh action shortcut"""

from pathlib import Path
import pythonista_add_action as actions

_stash = globals()["_stash"]


def _err(msg):
print(_stash.text_style(f"{msg}\n", {"color": "red", "traits": ["bold"]}))


def _info(msg):
print(_stash.text_style(f"{msg}\n", {"color": "green"}))


def _warn(msg):
print(_stash.text_style(f"{msg}\n", {"color": "yellow"}))


def _input(msg):
print(_stash.text_style(f"{msg}", {"color": "cyan"}), end="")
return input()


def create_or_update_action_stash(force_overwrite: bool = False) -> None:
"""
Creates or updates a shortcut for the 'stash' script in Pythonista's action menu.
"""
stash_action = {
"scriptName": "site-packages/stash/__main__.py",
"title": "StaSh",
"iconColor": "58C37D",
"iconName": "pythonista",
# "resetEnvironment": 1,
# "arguments": "stash"
}

script_path = stash_action["scriptName"]
full_script_path = Path("~").expanduser() / "Documents" / script_path
should_overwrite = False

if not full_script_path.exists():
_err(f"Error: The 'stash' script was not found at {full_script_path}.")
return

try:
current_actions = actions.get_actions()
script_names = [str(action["scriptName"]) for action in current_actions]

if script_path in script_names:
_warn("Warning: A 'StaSh' shortcut already exists.")
if not force_overwrite:
overwrite = _input("Do you want to overwrite it? [yes/no]: ").lower()
if overwrite in {"yes", "y"}:
should_overwrite = True
else:
_warn("Exiting: The 'StaSh' shortcut will not be updated.")
return
else:
should_overwrite = True

if should_overwrite:
_warn("Warning: The 'StaSh' shortcut will be updated.")
print("* Removing existing shortcut...")
index_to_remove = script_names.index(script_path)
actions.remove_action_at_index(index_to_remove)
print("* Existing shortcut removed.")

print("* Creating new shortcut...")
actions.add_action(**stash_action)
actions.save_defaults()
_info("Success: New 'StaSh' shortcut created.")

except Exception as e:
_err(f"Error: An error occurred: {e}")


if __name__ == "__main__":
import argparse

pa = argparse.ArgumentParser(
"pinstash", description="Create or update StaSh action shortcut"
)
pa.add_argument(
"-f", "--force", action="store_true", help="Force overwrite of shortcut"
)
args = pa.parse_args()
create_or_update_action_stash(args.force)
2 changes: 1 addition & 1 deletion bin/whatis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import json

file = '{"alias":"Define or print aliases","cat":"Print contents of file","cd":"Change current directory","clear":"Clear console","cp":"Copy file","crypt":"File encryption using AES in CBC mode","cowsay":"Generates ASCII picture of a cow with a message","curl":"Transfer from an URL","cut":"Cut out selection portions of each line of a file","du":"Summarize disk usage of the set of FILEs, recursively for directories","echo":"Output text to console","edit":"Open any text type files in Pythonista editor","find":"Powerful file searching tool","fg":"Bring a background job to foreground","ftpserver":"A simple FTP server","gci":"Interface to Pythons built-in garbage collector","git":"Git client","grep":"search contents of file(s)","head":"Display first lines of a file","httpserver":"A simple HTTP server with upload function","jobs":"List all jobs that are currently running","kill":"Terminate a running job","ls":"List files","mail":"Send emails with optional file attachment","man":"Show help message (docstring) of a given command","mc":"Easily work with multiple filesystems (e.g. local and FTP) synchronously","md5sum":"Print or check MD5 checksums","mkdir":"Create directory","monkeylord":"Manage monkey patches with the goal to make Pythonista more viable","mv":"Move file","openin":"Show the open in dialog to open a file in external apps","pbcopy":"Copy to iOS clipboard","pbpaste":"Paste from iOS clipboard","pip":"Search, download, install, update and uninstall pure Python packages from PyPI","printenv":"List environment variables","printhex":"Print hexadecimal dump of the given file","pwd":"Print current directory","python":"Run python scripts or modules","quicklook":"iOS quick look for files of known types","rm":"delete (remove) file","scp":"Copy files from/to remote servers","selfupdate":"Update StaSh from its GitHub repo","sha1sum":"Print of check SHA1 checksums","sha256sum":"Print of check SHA256 checksums","sort":"Sort a list, also see unique","source":"Evaluate a script in the current environment","ssh":"SSH client to either execute a command or spawn an interactive session on remote servers","ssh-keygen":"Generate RSA/DSA SSH Keys","stashconf":"Change StaSh configuration on the fly","tail":"Print last lines of a FILE","tar":"Manipulate archive files","touch":"Update timestamp of the given file or create it if not exist","uniq":"Remove duplicates from list, also see sort","unzip":"Unzip file","version":"Show StaSh installation and version information","wc":"Line, word, character counting","wget":"Get data from the net","whatis":"Search manual page databases","which":"Find the exact path to a command script","wol":"Wake on LAN using MAC address for launching a sleeping system","xargs":"Command constructing and executing utility","zip":"Zip file"}'
file = '{"alias":"Define or print aliases","cat":"Print contents of file","cd":"Change current directory","clear":"Clear console","cp":"Copy file","crypt":"File encryption using AES in CBC mode","cowsay":"Generates ASCII picture of a cow with a message","curl":"Transfer from an URL","cut":"Cut out selection portions of each line of a file","du":"Summarize disk usage of the set of FILEs, recursively for directories","echo":"Output text to console","edit":"Open any text type files in Pythonista editor","find":"Powerful file searching tool","fg":"Bring a background job to foreground","ftpserver":"A simple FTP server","gci":"Interface to Pythons built-in garbage collector","git":"Git client","grep":"search contents of file(s)","head":"Display first lines of a file","httpserver":"A simple HTTP server with upload function","jobs":"List all jobs that are currently running","kill":"Terminate a running job","ls":"List files","mail":"Send emails with optional file attachment","man":"Show help message (docstring) of a given command","mc":"Easily work with multiple filesystems (e.g. local and FTP) synchronously","md5sum":"Print or check MD5 checksums","mkdir":"Create directory","monkeylord":"Manage monkey patches with the goal to make Pythonista more viable","mv":"Move file","openin":"Show the open in dialog to open a file in external apps","pbcopy":"Copy to iOS clipboard","pbpaste":"Paste from iOS clipboard","pinstash":"Create or update StaSh action shortcut","pip":"Search, download, install, update and uninstall pure Python packages from PyPI","printenv":"List environment variables","printhex":"Print hexadecimal dump of the given file","pwd":"Print current directory","python":"Run python scripts or modules","quicklook":"iOS quick look for files of known types","rm":"delete (remove) file","scp":"Copy files from/to remote servers","selfupdate":"Update StaSh from its GitHub repo","sha1sum":"Print of check SHA1 checksums","sha256sum":"Print of check SHA256 checksums","sort":"Sort a list, also see unique","source":"Evaluate a script in the current environment","ssh":"SSH client to either execute a command or spawn an interactive session on remote servers","ssh-keygen":"Generate RSA/DSA SSH Keys","stashconf":"Change StaSh configuration on the fly","tail":"Print last lines of a FILE","tar":"Manipulate archive files","touch":"Update timestamp of the given file or create it if not exist","uniq":"Remove duplicates from list, also see sort","unzip":"Unzip file","version":"Show StaSh installation and version information","wc":"Line, word, character counting","wget":"Get data from the net","whatis":"Search manual page databases","which":"Find the exact path to a command script","wol":"Wake on LAN using MAC address for launching a sleeping system","xargs":"Command constructing and executing utility","zip":"Zip file"}'


def main():
Expand Down
Loading