From ba29b6e319a2a6fe8ee9788be9c7abef90173a4c Mon Sep 17 00:00:00 2001 From: Username Date: Sat, 20 Dec 2025 18:05:33 +0100 Subject: [PATCH] fpaste: encrypt by default, add file path shortcut Change encryption from opt-in (-e) to opt-out (-E/--no-encrypt). Add argument preprocessing to auto-insert "create" command when file path is detected, allowing `fpaste file.txt` shortcut. --- fpaste | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/fpaste b/fpaste index f36db35..a746c5b 100755 --- a/fpaste +++ b/fpaste @@ -216,9 +216,11 @@ def cmd_create(args, config): if not content: die("empty content") - # Encrypt content if requested + # Encrypt by default (unless --no-encrypt) encryption_key = None - if args.encrypt: + if not getattr(args, "no_encrypt", False): + if not HAS_CRYPTO: + die("encryption requires 'cryptography' package (use -E to disable)") if not args.quiet: print("encrypting...", end="", file=sys.stderr) content, encryption_key = encrypt_content(content) @@ -720,21 +722,40 @@ def main(): # Pre-process arguments: if first positional looks like a file, insert "create" args_to_parse = sys.argv[1:] commands = {"create", "c", "new", "get", "g", "delete", "d", "rm", "info", "i", "cert", "pki"} + top_level_opts = {"-s", "--server", "-h", "--help"} + + # Find insertion point for "create" command + insert_pos = 0 + has_command = False + file_pos = -1 - # Find first non-option argument i = 0 while i < len(args_to_parse): arg = args_to_parse[i] if arg in ("-s", "--server"): - i += 2 # Skip -s and its value + insert_pos = i + 2 # After -s value + i += 2 + continue + if arg in ("-h", "--help"): + i += 1 + insert_pos = i continue if arg.startswith("-"): + # Unknown option - might be for create subcommand i += 1 continue - # Found first positional - check if it's a command or a file - if arg not in commands and is_file_path(arg): - args_to_parse.insert(i, "create") - break + # Found positional argument + if arg in commands: + has_command = True + break + elif is_file_path(arg): + file_pos = i + break + i += 1 + + # Insert "create" before file path if no command found + if not has_command and file_pos >= 0: + args_to_parse.insert(insert_pos, "create") parser = argparse.ArgumentParser( prog="fpaste", @@ -751,7 +772,7 @@ def main(): # create p_create = subparsers.add_parser("create", aliases=["c", "new"], help="create paste") p_create.add_argument("file", nargs="?", help="file to upload (- for stdin)") - p_create.add_argument("-e", "--encrypt", action="store_true", help="encrypt content") + p_create.add_argument("-E", "--no-encrypt", action="store_true", help="disable encryption") p_create.add_argument("-b", "--burn", action="store_true", help="burn after read") p_create.add_argument("-x", "--expiry", type=int, metavar="SEC", help="expiry in seconds") p_create.add_argument("-p", "--password", metavar="PASS", help="password protect") @@ -835,7 +856,7 @@ def main(): if not sys.stdin.isatty(): args.command = "create" args.file = None - args.encrypt = False + args.no_encrypt = False # Encrypt by default args.burn = False args.expiry = None args.password = None