1

I'm getting started with creating my own VS Code extension by following this tutorial. After installing Yeoman and walking through the prompts, I'm told I can change directories to my extension with cd identifier:

To start editing with Visual Studio Code, use the following commands:

    cd identifier
    code-insiders .

After doing so, I came to learn that it didn't open the folder it had created, and, I had no idea where it put it. I did, have a relative path however, which was a start:

ComputerInfo ~/identifier
$

I was able to discover that this maps to my user folder on the machine by executing:

dirs ~/

However, this feels a bit "hackish" since I got an error, and that's what gave me the path:

ComputerInfo ~/identifier
$ dirs ~/
bash: dirs: /c/Users/Taco/: invalid option
dirs: usage: dirs [-clpv] [+N] [-N]

How can I properly determine the directory for ~/ in the VS Code terminal?

Hazel へいぜる
  • 2,751
  • 1
  • 12
  • 44
  • Have you seen https://stackoverflow.com/questions/31435921/difference-between-and ? I think that _sort of_ answers your question. – Timothy G. Aug 26 '21 at 16:55
  • @TimothyG. thanks for the reading material. :) I was already aware that it was relative pathing, but since I didn't have concrete pathing to infer the relative path from, I was having trouble finding the folder. – Hazel へいぜる Aug 26 '21 at 17:02

1 Answers1

1

Normally '~' is simply your home. if you type 'env' into a terminal you get a lengthy answer about all system settings. The interesting line for you is 'HOME=/home/'username'' . At least it is like that on my PC. There is a second way: type 'cd' (without any path. This takes you to your home. Next type 'pwd' (Present Work Directory). This command returns where you are.

  • P.S. VS probably has some kind of system call to execute operating system commands. At least the languages I know have this possibility. – Ricardo Erckert Aug 26 '21 at 16:57
  • I wonder how this holds up if you're working from a different drive? Great answer though! Wish I would've known this prior. – Hazel へいぜる Aug 26 '21 at 17:03
  • 1
    Normally this should be independent of the drive. The home directory is assigned to the user running the software. But you can do dirty things in a software such as executing a 'su' (switch user) command. Then the home of the new user will become assigned to '~'. – Ricardo Erckert Aug 26 '21 at 18:16
  • 1
    At least in UNIX and Linux like systems the '~' (home) is associated to the user rather than the drive used. But if the software runs with root privilege you can do dirty things like changing the home ('su' changes the user name! NOT RECOMMENDED to do this during software execution.) But I have no idea if this is the same for Windows. – Ricardo Erckert Aug 26 '21 at 18:30
  • "*Normally this should be independent of the drive.*"; I only asked because I noticed `HOMEDRIVE=C:` lol thanks for answering! – Hazel へいぜる Aug 26 '21 at 18:35