Skip to content

MyUstaadG

Learn to Serve

  • Computer Science
    • Software
    • Computer Tips
    • Coding
      • Conditional Structures Exercises
      • Loops Exercises
      • Arrays Exercises
      • Python Exercises
    • Microsoft Office
      • MS Excel
      • MS Word
  • Videos
    • Funny Videos
    • Health and Fitness Videos
    • PUBG Videos
    • Technology Videos
  • News
  • Funny
  • Memes
  • Playwright Tutorials
  • Tutorials
  • Toggle search form
how to create file faster in VS code

How To Create Files Faster in Visual Studio Code With a Command

Posted on February 19, 2022February 20, 2022 By myustaadg.com No Comments on How To Create Files Faster in Visual Studio Code With a Command
Spread the love

Today in this article, we will learn How To Create Files Faster in Visual Studio Code With a Command.

Creating files using a mouse on Visual Code seems like a lot of work so I mostly use UNIX commands; mkdir to make directories and touch to make files.

But the touch command only works when the file directory(s) (destination) exist(s).

So we will create a bash-alias to create a file and create the directory(s) from the path if they do not exist.

For instance:

[command] src/components/App.ts

# should create
- src/
  |
    -- components/
         |
         -- App.ts
  • create a shell script and paste this code into it:
#!/bin/bash

function t() {
    regex="([^/]+\/)"
    f=$1
    temp="./"

while [[ $f =~ $regex ]]; do
    name="${BASH_REMATCH[1]}"
    temp=$temp$name
    mkdir $temp -p
    f=${f#*"${BASH_REMATCH[1]}"}
done

touch $temp$f    
}
  • enable running commands from the file by adding it to bash aliases using this command below:
source ./path/to/your_bash_alias_file

# mine, for instance
source /temp/scripts/my_bash_alias.sh
  • Now, we can make use of t to created files and automatically create the paths to the file even if they do not exist:
t src/components/App.js

Conclusion:

The alias we created above is temporal only for testing the script out. To create an alias permanently add the alias to your .bashrc file.

And I also published an npm package to make use of the t command. by installing it globally with

npm install-g touch-alias.

Please, kindly star the repository if you find this helpful and leave a comment.

#vscode

#beginners

Hope You will learn Something. Happy Coding.

Visit my YouTube Channel as Well๐Ÿ˜‡ https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4

Click on the below Links for more Programming Exercises:

Conditional Structure Exercises: ๐Ÿ‘‰https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/

Computer Tips Tags:command line, How To Create Files Faster in Visual Studio code, How To Create Files Faster in Visual Studio code in unix, How To Create Files Faster in Visual Studio Code With a Command, visual studio code, vs code

Post navigation

Previous Post: Write a program to initialize values in two tables A and B. Multiply matrix A and B and store results into table C | Multiplication of matrices.
Next Post: Playwright Tutorial for Beginners 1 – Getting Started

More Related Articles

Top 10 Programming Languages Which You Must Learn Top 10 Programming Languages Which You Must Learn Computer Tips
How to Download tik-tok Videos Without Watermark | Download tik-tok Videos without logo How to Download tik-tok Videos Without Watermark | Download tik-tok Videos without logo Computer Tips
How to Adjust Spacing in Word ,Adjust Double Spacing in Word, Adjust Line Spacing in Word, Adjust Character Spacing in Word How to Adjust Spacing in Word | Adjust Double Spacing in Word | Adjust Line Spacing in Word | Adjust Character Spacing in Word Computer Tips
How to Download Videos from Youtube Without Any Download Manager How to Download Videos from Youtube Without Any Download Manager Computer Tips
playwright Tutorial No. 01 Playwright Tutorial for Beginners 1 – Getting Started Computer Tips
How to Convert MS Excel file into PDF File Excel to PDF Excel to PDF Conversion How to Convert MS Excel file into PDF File | Excel to PDF | Excel to PDF Conversion Computer Tips

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme