racket / drracket

DrRacket, IDE for Racket
http://www.racket-lang.org/
Other
444 stars 93 forks source link

Add default quickscripts #616

Open spdegabrielle opened 1 year ago

spdegabrielle commented 1 year ago

One of the features of DrRacket I am enthusiastic about is the Scripts capability.

I think it is fair to say that developers often find value in customising their tools to meet their needs.

The scripts functionality is a safe and beginner friendly way for new developers to do this without the risk of making change that negatively impacts their experience.

The list should be short - I would suggest the following would be sufficient

The impact on the Racket installer would be minimal:

#lang racket/base
(require racket/system
         racket/path
         quickscript)

(script-help-string "Open a terminal in the directory of the current file.")

(define-script open-terminal
  #:label "Open terminal here"
  #:menu-path ("&Utils")
  #:os-types (unix macosx windows)
  (λ (str #:file f)
    (unless f
      (set! f (current-directory)))
    (define dir (path->string (path-only f)))
    (case (system-type 'os)
      [(unix)
       (system (string-append "gnome-terminal"
                              " --working-directory=\"" dir "\""
                              " -t \"" dir "\""
                              "&"))]
      [(macosx)
       (system
        (string-append "osascript -e 'tell app \"Terminal\" to do script \"cd \\\"" dir "\\\"\"'" ))]
      [(windows)
       (shell-execute #f "cmd.exe" "" dir 'sw_shownormal)])
    #false))
(define-script more-scripts
  #:label "Get more scripts (browser)"
  #:menu-path ("url2script")
  #:help-string "Opens the Racket wiki page for DrRacket Quickscript scripts."
  (λ (str) 
    (send-url "https://github.com/racket/racket/wiki/Quickscript-Scripts-for-DrRacket")
    #f))
rfindler commented 1 year ago

This sounds great to me, but wouldn't this be a change in the quickscript repo? @Metaxal , what do you think?

Metaxal commented 1 year ago

@rfindler Yes, that would be a change to the quickscript repo. I guess @spdegabrielle started the issue here because your approval is the most important.

These 2 scripts are fine with me conceptually.

For the second one, perhaps removing the #:menu-path entry.

For the first one, gnome-terminal is also a little too specific. Unfortunately there is no standard way to ask for the 'default' terminal ($TERM is often not properly set). And the way they handle arguments of course varies. I'm not sure how to make this work universally. xterm may be more universal but the default configuration is really bare bones (no color).

spdegabrielle commented 1 year ago

I'd suggest that the experience of changing the code for your version of linux is not a big deal and gnome-terminal is probably good enough.

spdegabrielle commented 1 year ago

The users are developers - they will change it.

Metaxal commented 1 year ago

If the default script live in a subdirectory of the quickscript collection, then the file may be read-only.

But they would be writable if they are automatically 'installed' within the user's user-scripts directory, which is created the first time quickscript is run. The scripts won't be created upon installation, which is a little annoying (need to check for existence, etc.), but doable I guess.

gnome-terminal does not always exist on linux (only when Gnome is installed). So we sh/could also test for the existence of gnome-terminal. In KDE, the default terminal is Konsole apparently. For Xfce, it seems to be xfce4-terminal. Maybe covering these 3 cases is good enough, and then reverting to xterm in other cases. Although I guess if someone has installed both gnome and KDE, they will have both terminal emulators. Maybe that's good enough anyway.

spdegabrielle commented 1 year ago

I was thinking of a default-scripts package like q*-extra - but now it occurs to me the racket installer may not be able to install packages in user scope?

rfindler commented 1 year ago

Re terminal: it might be nice to have something that provides reasonable default for mac os and windows too (probably a case-dispatch on system-type and a few sets of different code).

Metaxal commented 1 year ago

Re terminal: it might be nice to have something that provides reasonable default for mac os and windows too (probably a case-dispatch on system-type and a few sets of different code).

It's already the case: look at the code at the top ;)

rfindler commented 1 year ago

Oh, duh! Sorry!

WRT to the unix version: how about putting a list of candidates and then illustrating find-executable-path?

Metaxal commented 1 year ago

Yup, good idea.

spdegabrielle commented 1 year ago

I’ll be honest I’m not looking at rewriting anything I just want to do the bare minimum to move things in what I consider is the right direction. Refinements are an opportunity for someone else to get involved. open-terminal works fine on windows, macOS and a significant proportion of linux systems - and fails in a predictable way that lets the user resolve it themselves and / or prompts them to contribute a better solution.

Metaxal commented 1 year ago

I'm okay to update the scripts. How about creating a new package/collection like quickscript-default-scripts? If there's no need to tweak the scripts, it's okay if it's not in the user's script directory.

spdegabrielle commented 1 year ago

Thank you @Metaxal