Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default quickscripts #616

Open
spdegabrielle opened this issue May 30, 2023 · 13 comments
Open

Add default quickscripts #616

spdegabrielle opened this issue May 30, 2023 · 13 comments

Comments

@spdegabrielle
Copy link
Member

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

  • Open terminal - opens the terminal in the current folder
  • Get more scripts - only the script that opens the wiki page with more scripts to review and install.

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
Copy link
Member

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

@Metaxal
Copy link
Contributor

Metaxal commented May 30, 2023

@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
Copy link
Member Author

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
Copy link
Member Author

The users are developers - they will change it.

@Metaxal
Copy link
Contributor

Metaxal commented May 30, 2023

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
Copy link
Member Author

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
Copy link
Member

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
Copy link
Contributor

Metaxal commented May 30, 2023

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
Copy link
Member

Oh, duh! Sorry!

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

@Metaxal
Copy link
Contributor

Metaxal commented May 30, 2023

Yup, good idea.

@spdegabrielle
Copy link
Member Author

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
Copy link
Contributor

Metaxal commented Jun 4, 2023

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
Copy link
Member Author

Thank you @Metaxal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants