commit 6b766e6549276590bcec115a32a6a00bc41ead59 from: mtmn date: Fri Aug 28 00:50:46 2026 UTC fix fzf and remove sx commit - 2b6aafdabcaf40106f641086b4414484c02c1a86 commit + 6b766e6549276590bcec115a32a6a00bc41ead59 blob - e9e5036cf087d5343b0cbd5a121280f5c1b858f3 blob + 978f0f887355fb0b72979f2de7997002ce5187df --- README.md +++ README.md @@ -47,15 +47,15 @@ p PORT allow outbound TCP connections to a destina d enter and remove an outbound TCP port c show global and local configuration file contents s save -sx save and exit immediately (xs also works) ? help x exit (discards any unsaved changes) ``` After you select `a`, enter a base path such as `/home/miro`. Press Enter to start in your home directory. `fzf` shows the path and its immediate child -directories. Press Enter to open a directory. Press Alt+Enter or Ctrl-S to -select it. Press Escape to use the path you entered. +directories. Press Enter to open a directory. Press Alt+Enter to select the +directory under the cursor. Press Ctrl-S to save the current directory. Press +Escape to use the path you entered. You cannot add the baseline writable tree again. blob - ce3f2aec5603520c0caa998b0008cc9b32a17d3d blob + 11d180712ace8005b1e22e65eed4c54e881ab6e2 --- doc/pisol.1 +++ doc/pisol.1 @@ -52,8 +52,9 @@ Prompt for a base directory path and add a read/write/ input, the picker opens in the user's home directory. When .BR fzf (1) is available, the picker lists the typed path and its immediate child -directories. Press Enter to open a directory. Press Alt+Enter or Ctrl-S to -select it. Press Escape to use the typed path directly. +directories. Press Enter to open a directory. Press Alt+Enter to select the +directory under the cursor. Press Ctrl-S to save the current directory. Press +Escape to use the typed path directly. .TP .B r Prompt for the number of a writable directory and remove it. @@ -69,11 +70,7 @@ Show the global init file and local configuration file contents. A missing file is labelled absent. .TP .B s -Save atomically with mode 0600. The combined commands -.B sx -and -.B xs -save and then exit immediately. +Save atomically with mode 0600. .TP .BR ? , " x" Show help or exit. Exit discards any unsaved changes. blob - 7c7c5257a49403faff5405a3ccb1398047305fb1 blob + 141b2d3a14bded8e4f707718e6d773d08d4056c4 --- src/pisol/tui.sls +++ src/pisol/tui.sls @@ -66,21 +66,27 @@ (and (file-exists? path) (call-with-input-file path (lambda (port) - (let ([first (get-line port)]) - (if (eof-object? first) - #f - (let ([second (get-line port)]) - (list first - (if (eof-object? second) #f second))))))))) + (let loop ([lines '()]) + (let ([line (get-line port)]) + (if (eof-object? line) + (reverse lines) + (loop (cons line lines))))))))) (define (read-text path) (call-with-input-file path get-string-all)) + (define (read-current-path path) + (and (file-exists? path) + (let ([content (read-text path)]) + (let ([trimmed (trim content)]) + (if (string=? trimmed "") #f trimmed))))) + (define (fuzzy-directory base) (if (or (not (terminal-input?)) (not (command-available? "fzf")) (not (file-directory? base))) base (let* ([output (temporary-path)] + [current-file (string-append output ".dir")] [fd? (command-available? "fd")] [child-list (lambda (dir) (if fd? @@ -95,12 +101,11 @@ (string-append "{ " initial "; } " "| fzf --scheme=path --layout=reverse --height=80% --border" - " --expect=esc" + " --expect=esc,ctrl-s" " --prompt='Directory path: '" - " --header='Enter drills down. Alt+Enter or Ctrl-S selects. Esc uses the typed path.'" - " --bind 'enter:reload(" reload ")+clear-query'" + " --header='Enter drills down. Alt+Enter selects the cursor item. Ctrl-S saves the current directory. Esc uses the typed path.'" + " --bind 'enter:execute-silent(printf %s '{+1}' > " (shell-quote current-file) ")+reload(" reload ")+clear-query'" " --bind 'alt-enter:accept'" - " --bind 'ctrl-s:accept'" " >" (shell-quote output))]) (dynamic-wind (lambda () #f) @@ -112,14 +117,17 @@ (let ([lines (read-output-lines output)]) (cond [(not lines) base] + [(null? lines) base] [(string=? (car lines) "esc") base] + [(string=? (car lines) "ctrl-s") (or (read-current-path current-file) base)] [else - (let ([selection (cadr lines)]) - (if (and selection (not (string=? (trim selection) ""))) + (let ([selection (car lines)]) + (if (not (string=? (trim selection) "")) selection base))]))]))) (lambda () - (when (file-exists? output) (delete-file output))))))) + (when (file-exists? output) (delete-file output)) + (when (file-exists? current-file) (delete-file current-file))))))) (define (choose-directory) (let* ([home (getenv "HOME")] @@ -209,7 +217,7 @@ (newline) (display "a add dir r remove dir p add port d remove port") (newline) - (display "s save sx save exit c show config ? help x exit") + (display "s save c show config ? help x exit") (newline) (when (configuration-dirty? configuration) (display (yellow "unsaved changes")) @@ -285,18 +293,18 @@ (if (and port (remove-port! configuration port)) (loop (format "removed outbound TCP port ~a" port)) (loop "configured port not found")))))] - [(or (string=? command "s") (string=? command "sx") (string=? command "xs")) + [(string=? command "s") (cond [(not (configuration-dirty? configuration)) - (if (string=? command "s") (loop "nothing to save") #t)] + (loop "nothing to save")] [(and (eq? (configuration-source-style configuration) 'custom) (not (yes? "Replace custom shell with canonical evaluated arguments?"))) - (if (string=? command "s") (loop "save cancelled") #t)] + (loop "save cancelled")] [else (guard (condition (else (loop (format "save failed: ~a" condition)))) (save-configuration! configuration) - (if (or (string=? command "sx") (string=? command "xs")) #t (loop "saved .isolate")))])] + (loop "saved .isolate"))])] [(string=? command "?") (show-help) (loop "")] [(string=? command "c") (show-config-files configuration) (loop "")] [(string=? command "x") #t]