Skip to content
On this page

VSCode

  • maybe call it .pub? or pub_
  • Karbiner?
  • AHK shortcuts?

Snippets

root

bash
code --user-data-dir="/root/.vscode-root-no-sandbox" --no-sandbox
  • vscode docs was interesting how it opened up

when

txt
"when": "editorLangId == markdown"

VSCode Run Active File

  • language is the bottom auto-detect thing
  • "when": "resourceLangId == shellscript",
  • "when": "resourceLangId == yaml",

workspace

Details
js
// https://code.visualstudio.com/docs/terminal/advanced
// https://code.visualstudio.com/docs/editor/variables-reference
const testVars = [
  {
    "key": "ctrl+u",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
      "text": "\u001b[1;5D\u007f"
    }
  },
  {
    /** echo hi */
    "key": "ctrl+`",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
      "text": "echo hi\u000D" // \u000D is enter \r
    }
  },
  {
    "key": "ctrl+enter",
    "command": "workbench.action.terminal.runActiveFile"
    ///*up enter*/ "command": "workbench.action.terminal.sendSequence","args": {"text": "\u001b[A\u000D"}
  },
  //ideally to have some util script that gets called that should just check some ENV
  {
    /** wsl */
    "key": "ctrl+`",
    // "key": "ctrl+r",
    // "key": "ctrl+enter",
    "command": "workbench.action.terminal.sendSequence",
    "when": "editorTextFocus",
    // "when": "editorTextFocus && resourceLangId ",
    "args": {
      //pwsh terminal
      // "text": "echo hi\u000D"
      // "text":"echo `wslpath \"${file}\"`\u000D"
      // "text":"zsh $(wslpath \"${file}\")\u000D", //defn works for wsl
      "text":"echo `/cygdrive/c/cygwin64/bin/cygpath.exe \"${file}\"`\u000D"
      // "text":"echo `/mnt/c/cygwin64/bin/cygpath.exe \"${file}\"`\u000D" //wsl inside cygwin
      // "text":"echo ${file}"
    }
  },
  {
    /** q ctrl+c */
    "key": "ctrl+`",
    "command": "workbench.action.terminal.sendSequence",
    "when": "editorTextFocus",
    // "when": "editorTextFocus && resourceLangId === 'sh'",
    "args": {
      "text":"q\u0003"
    }
  },
]
bash
// Place your key bindings in this file to override the defaultsauto[]
[
  // {
    //     "key": "alt+enter",
    //     "command": "workbench.action.terminal.runActiveFile"
    //   },

    {
      /** ahk cygwin */
      "key": "ctrl+enter",
      "command": "workbench.action.terminal.sendSequence",
      "when": "resourceLangId == ahk2",//use brackets
      "args":{
        "text":"c:/Users/Jason/AppData/Local/Programs/AutoHotkey/v2/AutoHotkey64.exe \"${file}\"\u000D" //defn works
      }
    },
    
    {
      /** q ctrl+c */
      "key": "ctrl+`",
      "command": "workbench.action.terminal.sendSequence",
      "when": "editorTextFocus&& terminalProcessSupported",
      // "when": "editorTextFocus && resourceLangId === 'sh'",
      "args": {
        "text":"\u0003" //^C # and when supported i guess
        // "text":"\u0004" //^D ... it's off by 1?
        // "text":"q"
      }
    },
    {
      /** rasa */
      "key": "ctrl+enter",
      "command": "workbench.action.terminal.sendSequence",
      "when": "resourceLangId == yaml",
      "args":{
        "text":"rasa_hostcfg_apply \"${file}\"\u000D" //defn works
      }
    },
    {
      "key": "ctrl+enter",
      "command": "workbench.action.terminal.runActiveFile",
      "when": "resourceLangId == shellscript",
    },
    {
      "key": "ctrl+enter",
      // "command": "-workbench.action.terminal.runActiveFile",
      "command": "workbench.action.terminal.sendSequence",
      "args":{
        // "text":"echo \"${file}\"\u000D" //defn works
        // "text":"echo hi\u000D" //defn works
        "text":"'c:/Users/Jason/WebstormProjects/vite-press-docs/src/demo-rec-utils/generate-demo-scripts/bin-templates/a_demo_current/split-screen-runner.sh'\u000D" //defn works
      },
      "when": "resourceFilename == 'split-screen.sh'",
    },
    //end rasa... maybe just need different profile in all honesty
    {
      /** wsl */
      // "key": "ctrl+`",
      // "key": "ctrl+r",
      "key": "ctrl+enter",
      "command": "workbench.action.terminal.sendSequence",
      // "command": "-workbench.action.terminal.sendSequence",
      // "when": "editorTextFocus",
      "when": "resourceLangId == yaml",
      /* yaml ps1 / cygwin? */
      "args":{
        "text":"rasa_hostcfg_apply \"${file}\"\u000D" //defn works
      }
      
      /**/
      // "argss": {
        
        //   //pwsh terminal
        //   // "text": "echo hi\u000D"
        //   // "text":"zsh $(wslpath \"${file}\")\u000D"
        //   // "text":"zsh $(wslpath \"${file}\")\u000D"
        //   // "text":"echo `/cygdrive/c/cygwin64/bin/cygpath.exe \"${file}\"`\u000D"
        //   // "text":"echo `/mnt/c/cygwin64/bin/cygpath.exe \"${file}\"`\u000D" //wsl inside cygwin
        //   // "text":"echo ${file}"
        // }
        /* wsl */
        // "args":{
          //   "text":"zsh $(wslpath \"${file}\")\u000D" //defn works
          // }
        },
        {
          "key": "ctrl+enter",
          // "command": "workbench.action.terminal.runActiveFile",
          "command": "workbench.action.terminal.runActiveFile",
          // "command": "-workbench.action.terminal.runActiveFile"
          ///*up enter*/ "command": "workbench.action.terminal.sendSequence","args": {"text": "\u001b[A\u000D"}
        },
        // {
          //   //testing send - clear might be better
          //   "key": "ctrl+`",
          //   "command": "workbench.action.terminal.sendSequence",
          //   "args": {"text": "\u0003"},//ctrl+c, read-host better. nginx just wont exit
          //   "when": "editorTextFocus",
          //   // "args": {"text": "\u001B[3~"},//ctrl+break, read-host better. nginx just wont exit
          //   // "args": {"text": "\u001B[15;5~"},//ctrl+break, read-host better. nginx just wont exit
          // },
          {
            //testing send - clear might be better
            // "key": "ctrl+`",
            "key": "ctrl+shift+`",
            "when": "!terminalFocus",
            // "when": "terminalFocus&&editorTextFocus",//false
            // "when": "terminalFocus&&editorTextFocus",//false
            // "command:":"-workbench.action.terminal.sendSequence"
            "command": "workbench.action.terminal.sendSequence",
            "args": {"text": "\u0003"},//ctrl+c, read-host better. nginx just wont exit
            // "args": {"text": "\u001B[3~"},//ctrl+break, read-host better. nginx just wont exit
            // "args": {"text": "\u001B[15;5~"},//ctrl+break, read-host better. nginx just wont exit
          },
          {
            //run selected test
            // "key": "ctrl+shift+enter",
            "key": "ctrl+r",
            "command": "workbench.action.terminal.runSelectedText",
            // "command": "terminal.external.windowsExec", //didnt work
            "when": "editorTextFocus && !editorReadonly"
          },
          /* repeated */
          // {
            //   "key": "alt+enter",
            //   "command": "& 'c:\\Users\\jason\\vsCode\\ahk_psexec\\exec_ahk.ps1'"
            // },
            {
              "key": "alt+enter",
              // "command": "code-runner.runCustomCommand"
              // "command": "code-runner.run"
              "command": "workbench.action.terminal.sendSequence","args": {"text": "\u001b[A\u000D"}
              // "command": "workbench.action.terminal.runActiveFile"
            },
            {
              "key": "alt+r",//maybe just numpad 
              // "command": "code-runner.runCustomCommand"
              // "command": "workbench.action.terminal.runRecentCommand",//i think this always gives the history
              "command": "workbench.action.terminal.sendSequence","args": {"text": "\u001b[A\u000D"}
            },
            {
              "key": "ctrl+alt+d",//maybe just numpad 
              "command": "workbench.action.terminal.sendSequence",//docs for sendSequence are at https://code.visualstudio.com/docs/editor/integrated-terminal#_send-text-to-the-terminal
              "args": {"text": "\u0003"}//EOF / ctrl+c in ssh
              // "args": {"text": "\u0004"}//EOF / ctrl+d in ssh
            },
            // https://code.visualstudio.com/docs/terminal/advanced
            //apparently can chain commands... interesting
            { 
            "key": "ctrl+w",       
            "command": "editor.action.smartSelect.expand",
            "when": "editorTextFocus" 
          },
          { "key": "ctrl+d",        "command": "editor.action.copyLinesDownAction",
          "when": "editorTextFocus && !editorReadonly"
        },
        {
          "key": "ctrl+shift+n",
          "command": "workbench.action.findInFiles"
        },
        { 
        "key":"alt+backspace",          
        "command": "editor.action.deleteLines",
        "when": "textInputFocus && !editorReadonly" 
      },
      {
        "key": "alt+f2",
        "command": "editor.action.inlineSuggest.trigger",
        "when": "config.github.copilot.inlineSuggest.enable && editorTextFocus && !editorHasSelection && !inlineSuggestionsVisible"
      },
      {
        "key": "alt+\\",
        "command": "-editor.action.inlineSuggest.trigger",
        "when": "config.github.copilot.inlineSuggest.enable && editorTextFocus && !editorHasSelection && !inlineSuggestionsVisible"
      },
      {
        "key": "ctrl+alt+f2",
        "command": "workbench.action.askCommandInInteractiveSession"
      },
      {
        "key": "shift+alt+up",
        "command": "editor.action.moveLinesUpAction",
        "when": "editorTextFocus && !editorReadonly"
      },
      {
        "key": "alt+up",
        "command": "-editor.action.moveLinesUpAction",
        "when": "editorTextFocus && !editorReadonly"
      },
      {
        "key": "shift+alt+down",
        "command": "editor.action.moveLinesDownAction",
        "when": "editorTextFocus && !editorReadonly"
      },
      {
        "key": "alt+down",
        "command": "-editor.action.moveLinesDownAction",
        "when": "editorTextFocus && !editorReadonly"
      },
      //terminal focus. might what to do a when cmd to toggle
      {
        "key": "ctrl+shift+j",
        "command": "terminal.focus"
      },
      {
        "key": "ctrl+`",
        "command": "-workbench.action.terminal.toggleTerminal",
        "when": "terminal.active"
      },
      // {
        //   "key": "ctrl+tab",
        //   "command": "workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup",
        //   "when": "!activeEditorGroupEmpty"
        // },
        // {
          //   "key": "ctrl+tab",
          //   "command": "workbench.action.quickOpenNavigateNextInEditorPicker",
          //   "when": "inEditorsPicker && inQuickOpen"
          // },
          {
            //ctrl-o tmux temporary
            "key": "ctrl+tab",
            "command": "workbench.action.terminal.sendSequence",
            "args": {"text": "\u000F"},
            // "when": "!activeEditorGroupEmpty"
            "when": "terminalFocus"
          },
          {
            "key": "ctrl+tab",
            // "command": "-workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup",
            "command": "workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup",
            // "when": "!activeEditorGroupEmpty"
            "when": "!terminalFocus && !activeEditorGroupEmpty"
          },
          {
            "key": "ctrl+tab",
            // "command": "-workbench.action.quickOpenNavigateNextInEditorPicker",
            "command": "workbench.action.quickOpenNavigateNextInEditorPicker",
            // "when": "inEditorsPicker && inQuickOpen"
            "when": "inEditorsPicker && inQuickOpen && !terminalFocus"
          },
          {
            "key": "ctrl+tab",
            "command": "-workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup",
            "when": "!activeEditorGroupEmpty"
          },
          {
            "key": "ctrl+tab",
            "command": "-workbench.action.quickOpenNavigateNextInEditorPicker",
            "when": "inEditorsPicker && inQuickOpen"
          },
          {
            "key": "alt+]",
            "command": "-editor.action.inlineSuggest.showNext",
            "when": "inlineSuggestionVisible && !editorReadonly"
          },
          {
            "key": "alt+[",
            "command": "-editor.action.inlineSuggest.showPrevious",
            "when": "inlineSuggestionVisible && !editorReadonly"
          },
          {
            "key": "ctrl+/",
            "command": "-github.copilot.acceptCursorPanelSolution",
            "when": "github.copilot.activated && github.copilot.panelVisible"
          },
          {
            "key": "ctrl+0",
            "command": "workbench.action.editorLayoutSingle"
          },
          {
            "key": "alt+]",
            "command": "-editor.action.accessibleViewNext",
            "when": "accessibleViewIsShown"
          },
          {
            "key": "alt+[",
            "command": "-editor.action.accessibleViewPrevious",
            "when": "accessibleViewIsShown"
          },
          {
            "key": "alt+\\",
            "command": "github.copilot.generate",
            "when": "editorTextFocus && github.copilot.activated && !inInteractiveInput && !interactiveEditorFocused"
          },
          {
            "key": "ctrl+enter",
            "command": "-github.copilot.generate",
            "when": "editorTextFocus && github.copilot.activated && !inInteractiveInput && !interactiveEditorFocused"
          },
          {
            "key": "ctrl+shift+c",
            "command": "-workbench.action.terminal.openNativeConsole",
            "when": "!terminalFocus"
          },
                    /*
           ctrl+numpad0 start 
           0 - unsplit
           1 - Close others
           2 - 
           
           s - save-repo
           */
           //double numpad 0 doesnt work? or wrong action. says terminal
          {
            //this closes the "editors" i guess but not the tabs in this group
            //
            "key": "ctrl+numpad0 ctrl+numpad0",
            "command": "workbench.action.closeEditorsInOtherGroups"
            //closeOtherEditors and closeEditorsInOtherGroups
          },
          // find the right one? i want to close other tabs in this group
          {
            "key": "ctrl+numpad0 ctrl+numpad1",
            // "command": "workbench.action.closeEditorsInGroup"//not this, this closes everything
            "command": "workbench.action.closeOtherEditors",
          },
          {
            "key": "ctrl+numpad0 ctrl+s",
            "command": "workbench.action.terminal.sendSequence",
            "args": {
              // "text": "git add .\u000Dgit commit -m \"auto\"\u000Dgit push\u000D"
              /* enter or cr */
              "text": "save-repo\u000D"
            }
          },
          //end
          {
            "key": "ctrl+numpad8",
            "command": "workbench.action.splitEditorUp"
          },
          {
            "key": "ctrl+k ctrl+\\",
            "command": "-workbench.action.splitEditorUp"
          },
          //probably the one i use most... would be enter selection
          // i.e. if we need more keys use ctrl+5 ctrl+5 or just 5
          {
            "key": "ctrl+numpad5",
            "command": "workbench.action.splitEditorDown"
          },
          {
            "key": "ctrl+k ctrl+\\",
            "command": "-workbench.action.splitEditorDown"
          },
          {
            "key": "ctrl+numpad4",
            "command": "workbench.action.splitEditorLeft"
          },
          {
            "key": "ctrl+k ctrl+\\",
            "command": "-workbench.action.splitEditorLeft"
          },
          {
            "key": "ctrl+numpad6",
            "command": "workbench.action.splitEditorRight"
          },
          {
            "key": "ctrl+k ctrl+\\",
            "command": "-workbench.action.splitEditorRight"
          },
          {
            "key": "ctrl+numpad_decimal",
            "command": "github.copilot.interactiveEditor.fix"
          },
          //break? dont think this works
          //https://stackoverflow.com/questions/45257525/make-ctrlc-copy-and-ctrlshiftc-interrupt-in-vscode-terminal
          // {
            //   "key": "ctrl+shift+c",
            //   "command": "workbench.action.terminal.sendSequence",
            //   "args": {
              //     "text": "\u0003"
              //   },
              //   "when": "terminalFocus && terminalProcessSupported"
              // }
              
            ]

Run Active file wsl / cygwin

  • todo add to the path thing

Variables Reference

txt
${file} - /home/your-username/your-project/folder/file.ext
${fileDirname} - /home/your-username/your-project/folder

${cwd} - the task runner's current working directory upon the startup of VS Code
js
let userHome,workspaceFolder,workspaceFolderBasename,file,
  fileWorkspaceFolder,relativeFile,relativeFileDirname,fileBasename,fileBasenameNoExtension,
  fileExtname,fileDirname,fileDirnameBasename,cwd,lineNumber,selectedText,execPath,defaultBuildTask,pathSeparator

const tmp =`
Predefined variables
The following predefined variables are supported:

${userHome} - the path of the user's home folder
${workspaceFolder} - the path of the folder opened in VS Code
${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)
${file} - the current opened file
${fileWorkspaceFolder} - the current opened file's workspace folder
${relativeFile} - the current opened file relative to workspaceFolder
${relativeFileDirname} - the current opened file's dirname relative to workspaceFolder
${fileBasename} - the current opened file's basename
${fileBasenameNoExtension} - the current opened file's basename with no file extension
${fileExtname} - the current opened file's extension
${fileDirname} - the current opened file's folder path
${fileDirnameBasename} - the current opened file's folder name
${cwd} - the task runner's current working directory upon the startup of VS Code
${lineNumber} - the current selected line number in the active file
${selectedText} - the current selected text in the active file
${execPath} - the path to the running VS Code executable
${defaultBuildTask} - the name of the default build task
${pathSeparator} - the character used by the operating system to separate components in file paths
Predefined variables examples
Supposing that you have the following requirements:

A file located at /home/your-username/your-project/folder/file.ext opened in your editor;
The directory /home/your-username/your-project opened as your root workspace.
So you will have the following values for each variable:

${userHome} - /home/your-username
${workspaceFolder} - /home/your-username/your-project
${workspaceFolderBasename} - your-project
${file} - /home/your-username/your-project/folder/file.ext
${fileWorkspaceFolder} - /home/your-username/your-project
${relativeFile} - folder/file.ext
${relativeFileDirname} - folder
${fileBasename} - file.ext
${fileBasenameNoExtension} - file
${fileDirname} - /home/your-username/your-project/folder
${fileExtname} - .ext
${lineNumber} - line number of the cursor
${selectedText} - text selected in your code editor
${execPath} - location of Code.exe
${pathSeparator} - / on macOS or linux, \ on Windows
`

VSCode Tunnel

  • to move
  • also maybe better to add the alias code. or change it to code-cli
bash
# unset / unalias if code exists
which code
which code | grep /usr/local/bin/code && echo done
# my script - think it shuold be under opt
sudo mkdir -p /srv/shared
sudo mkdir -p /srv/shared/downloads
sudo ls -l /srv/shared # root:root
sudo chgrp users /srv/shared
sudo chgrp -R users /srv/shared
sudo chmod -R 2775 /srv/shared
cd /srv/shared/downloads
# either ln or move code...
# it's only alpine wtf. but let's see
sudo curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz

sudo tar -xf vscode_cli.tar.gz
sudo ln -s /srv/shared/downloads/code /usr/local/bin/code # not sure if i want this though...

####

alias code=/usr/local/bin/code
unalias code
code --version
code tunnel service install
# follow
### 
code tunnel --help
code tunnel --accept-server-license-terms

code tunnel service log | grep -i status
code tunnel service log --help

# let's see how long it takes
code tunnel service uninstall

# keyring failed
# didnt ask for this:. also --no-sleep
# also zbus error...
sudo loginctl enable-linger $USER

VSCode Tunnel dup

  • duplicated
bash
# unset / unalias if code exists
which -a code
which code
which code | grep /usr/local/bin/code && echo done
# my script - think it shuold be under opt
sudo mkdir -p /srv/shared
sudo mkdir -p /srv/shared/downloads
sudo ls -l /srv/shared # root:root
sudo chgrp users /srv/shared
sudo chgrp -R users /srv/shared
sudo chmod -R 2775 /srv/shared
cd /srv/shared/downloads
# either ln or move code...
# it's only alpine wtf. but let's see
sudo curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz

sudo tar -xf vscode_cli.tar.gz
sudo ln -s /srv/shared/downloads/code /usr/local/bin/code # not sure if i want this though...

####

which code | grep /usr/local/bin/code && echo done || echo alias needed
alias code=/usr/local/bin/code
code --version
code tunnel service --verbose
code tunnel service help

code tunnel service log
code tunnel service install
# follow
code tunnel service uninstall
### 
code tunnel --help
code tunnel --accept-server-license-terms
code tunnel service log | grep -i status
code tunnel service log | grep -i "not found"
systemctl --user daemon-reload #
# let's see how long it takes
# ssh into the user is probably the easiest
# sudo systemctl status
systemctl status --no-pager
systemctl status --no-pager | grep -i -e "code/cli tunnel service"
code tunnel service uninstall
systemctl --user enable dbus --now
sudo systemctl --user enable dbus --now
# keyring failed
# didnt ask for this:. also --no-sleep
# also zbus error...
sudo loginctl enable-linger $USER
Failed to connect to bus: Operation not permitted (consider using --machine=<user>@.host --user to connect to bus of other user)
- Install the `dbus-user-session` package, and reboot if it was not installed
- Start the user dbus session with `systemctl --user enable dbus --now`.
bash
sudo apt install  -y dbus-user-session
XDG_RUNTIME_DIR=/run/user/0/
export XDG_RUNTIME_DIR=/run/user/0/
printenv XDG_RUNTIME_DIR