Write the package of user commands on the first interactive start
When $XDG_CONFIG_HOME/bjosh/commands is not there, an interactive bjosh writes it with the example, then builds and loads it. An empty directory turns this off. --new-commands stays, for a start that is not interactive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
aa5bae96e0
commit
bf961b12f9
4 changed files with 38 additions and 10 deletions
17
src/main.bjo
17
src/main.bjo
|
|
@ -10,13 +10,17 @@
|
|||
;; bjosh FILE ARG... runs the lines of FILE, with $0 FILE, $1 ARG...
|
||||
;; bjosh --new-commands
|
||||
;; writes a package of user commands, with an
|
||||
;; example; see (bjosh user)
|
||||
;; example; see (bjosh user). The first interactive
|
||||
;; start does this too.
|
||||
;;
|
||||
;; The exit code is the status of the last line, or the code of `exit`.
|
||||
;;
|
||||
;; - An interactive shell first runs the lines of the start-up file,
|
||||
;; $XDG_CONFIG_HOME/bjosh/rc or ~/.config/bjosh/rc.
|
||||
;; - Each bjosh loads the user's commands first, when there are any.
|
||||
;; - An interactive bjosh writes the package of user commands, with an
|
||||
;; example, when its directory is not there. An empty directory there
|
||||
;; turns this off.
|
||||
;; - The prompt is $PROMPT when it is set (see `custom-prompt`), else the
|
||||
;; user's prompt function, else the directory and $.
|
||||
|
||||
|
|
@ -85,6 +89,16 @@
|
|||
(def color (if (= (record-ref sh status) 0) "32" "31"))
|
||||
(str "\u{1B}[1;34m" (shown-directory) "\u{1B}[0m \u{1B}[" color "m$\u{1B}[0m "))
|
||||
|
||||
;; Writes the package of user commands, with its example, when its
|
||||
;; directory is not there. For an interactive start.
|
||||
(: (-> void))
|
||||
(defun (set-up-commands)
|
||||
(unless (directory-exists? (commands-dir))
|
||||
(match (write-example)
|
||||
(None (println (str "bjosh: wrote your commands to " (commands-dir) "/src/commands.bjo."
|
||||
" Edit them there, then run reload. Building them the first time...")))
|
||||
((Some message) (shell-error message)))))
|
||||
|
||||
;; Loads the user's commands into `sh`. A failure writes its message.
|
||||
(: (-> Shell Shell))
|
||||
(defun (with-extension sh)
|
||||
|
|
@ -156,6 +170,7 @@
|
|||
(def path (history-path))
|
||||
(ignore (line-history-load! ed path))
|
||||
(ignore (try (directory-create (path-combine path "..")) #:catch (System.Exception)))
|
||||
(set-up-commands)
|
||||
(def sh (with-extension (make-shell jc (Some ed) ["bjosh"])))
|
||||
(def rc (rc-path))
|
||||
(when (file-exists? rc)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue