Skip to content

Instantly share code, notes, and snippets.

@PetrChudoba
Last active August 25, 2022 23:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PetrChudoba/35bebd6c6f0f5cc81597798e7e64ce3d to your computer and use it in GitHub Desktop.
Save PetrChudoba/35bebd6c6f0f5cc81597798e7e64ce3d to your computer and use it in GitHub Desktop.
Visual Studio Code - CodeRunner - Run shellscripts with WSL.

Executor for shellscript

We need to convert Windows path to WSL path: C:\Users\user\Documents\script.sh -> /mnt/c/Users/user/Documents/script.sh

 "shellscript": "bash $('/mnt/' + $fullFileName.Substring(0,1).ToLower() + $fullFileName.Substring(2).Replace('\\','/') )",

Full settings.json

// Place your settings in this file to overwrite the default settings
{
    "code-runner.executorMap": {
        "javascript": "node",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "php": "php",
        "python": "python",
        "perl": "perl",
        "perl6": "perl6",
        "ruby": "ruby",
        "go": "go run",
        "lua": "lua",
        "groovy": "groovy",
        "powershell": "powershell -ExecutionPolicy ByPass -File",
        "bat": "cmd /c",
        "shellscript": "bash $( '/mnt/' + $fullFileName.Substring(0,1).ToLower()   +  $fullFileName.Substring(2).Replace('\\','/')   ) ",        "csharp": "scriptcs",
        "vbscript": "cscript //Nologo",
        "typescript": "ts-node",
        "coffeescript": "coffee",
        "scala": "scala",
        "swift": "swift",
        "julia": "julia",
        "crystal": "crystal",
        "ocaml": "ocaml",
        "r": "Rscript",
        "applescript": "osascript",
        "clojure": "lein exec",
        "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
        "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
        "racket": "racket",
        "ahk": "autohotkey",
        "autoit": "autoit3",
        "dart": "dart",
        "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
        "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
        "haskell": "runhaskell",
        "nim": "nim compile --verbosity:0 --hints:off --run"
    },
    "code-runner.runInTerminal": true
}
@marcbeshay
Copy link

And if you don't want Code Runner to run in terminal, you can use
"shellscript": "bash \"$(wslpath -a $fullFileName)\""
and
"code-runner.runInTerminal": false
Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment