pmatos / racket-news

Repository for the Racket News Website
https://racket-news.com
11 stars 2 forks source link

DrRacket [Quickscript](https://docs.racket-lang.org/quickscript/) of the day #39

Closed spdegabrielle closed 3 years ago

spdegabrielle commented 3 years ago

DrRacket Quickscript of the day

This issue we have two classics that I use every day, Open file directory that opens the files folder in you OS's GUI Finder/File Explorer/etc. (code below), and Open terminal here that opens a command line terminal set the the directory/folder of the currently selected file.

Both are available in the quickscript-extra package and are easily installed: Using the the graphical package manger in DrRacket (File>Package manager) enter quickscript-extra in the Source field, or, from the command line,raco pkg install quickscript-extra.

If DrRacket is already running, click on Scripts|Manage scripts|Compile scripts and reload menu.

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

(script-help-string "Open the system's file browser in the current directory.")

(define cmd
  (case (system-type 'os)
    [(unix)    "xdg-open"] ; or maybe mimeopen -n ?
    [(windows) "explorer"]
    [(macosx)  "open"]))

(define-script open-file-directory
  #:label "Open file directory"
  #:menu-path ("&Utils")
  (λ (str #:file f)
    (system (string-append cmd " \"" (path->string (path-only f)) "\""))
    #f))

Quickscript is included in DrRacket, and scripts are managed by the Script menu. See the documentation at https://docs.racket-lang.org/quickscript/

Stephen De Gabrielle