BashSnippets is a Visual Studio Code extension that provides a collection of snippets for bash scripting.
Here is a list of all the snippets and their triggers included in this extension:
shebang: Shebange: Echofn: Functionfnd: Function in a library with definitions of params and exportsif: if blockife: if else blockelif: elif blockuntil: until blockmain: a main function declaration with passthrough of all parameters passed to the fileconst: creates a local readonly variable ie. a constant (this is meant for use within functions only)todo: creates a local readonly variable ie. a constantarray: Creates an array with two elementsforarray: Creates a loop echoing all variables in an arrayforindex: Creates a loop echoing all indexes in a rangewhile: while loopcase: case statementfor: for loopread: read inputparam: parameter expansiontrap: trap statementhere: here documentherestring: here stringherestringdelim: here string with delimiterheredocdelim: here document with delimiterheredocEOF: here document with EOFheredocEOFdelim: here document with EOF and delimiterherestringEOF: here string with EOFherestringEOFdelim: here string with EOF and delimiterherestringdelim: here string with delimiterexport: Export a variablesource: Source a filealias: Create an aliastest: Test conditionparamsub: Parameter expansion with substringparamrep: Parameter expansion with pattern replacementparamlen: Parameter expansion with length of variableparamdef: Parameter expansion with default valueparamasg: Parameter expansion with assignment of default valueparamerr: Parameter expansion with error message if variable is unset or nullparamsuf: Parameter expansion with removal of smallest suffix patternparambig: Parameter expansion with removal of largest suffix patternparampre: Parameter expansion with removal of smallest prefix patternparambigpre: Parameter expansion with removal of largest prefix patternparamrepdef: - Parameter expansion with replacement and default valuecd: - Change directorymkdir: - Make directorytouch: - Create a new filerm: - Remove a filels: - List directory contentsgrep: - Search for a pattern in a filefind: - Find files in a directorytar: - Create a tar archiveuntar: - Extract a tar archivewget: - Download a file from the internetcurl: - Transfer data from or to a serverchmod: - Change file permissionschown: - Change file owner and groupchgrp: - Change file groupps: - List running processeskill: - Kill a processtop: - Display Linux processesfree: - Display amount of free and used memory in the systemdf: - Display disk usagedu: - Display disk usage statisticsuname: - Print system informationdate: - Display the system date and timeuptime: - Show how long the system has been runningwho: - Show who is logged onw: - Show who is logged on and what they are doingfinger: - Display information about userid: - Print real and effective user and group IDslast: - Show last logins of users and ttyswhoami: - Print the effective useridgroups: - Print the groups a user is inhostname: - Print the system hostnamedmesg: - Print or control the kernel ring bufferlsmod: - Show the status of modules in the Linux Kernellspci: - List all PCI deviceslsusb: - List all USB deviceslscpu: - Display information about the CPU architecturelsblk: - List block deviceslshw: - List hardwarelsscsi: - List SCSI deviceslsdev: - List deviceschecknet: - Check if the internet is on or offchecknetdns: - Check if the internet is on or off using DNSchecknetdnsretry: - Check if the internet is on or off using DNS and retry every 5 secondschecknetdnsretrytimeout: - Check if the internet is on or off using DNS and retry every 5 seconds with a timeout of 60 secondschecknetdnsretrytimeouterr: - Check if the internet is on or off using DNS and retry every 5 seconds with a timeout of 60 seconds and an error messagechecknetdnsretrytimeouterrex: - Check if the internet is on or off using DNS and retry every 5 seconds with a timeout of 60 seconds and an error message and exitcasepattern: - case statement with pattern matchingselect: - select loop for menu-like interfacesgetopts: - getopts loop for processing command-line optionsfileexist: - check if a file existsdirexist: - check if a directory existsfileread: - check if a file is readablefilewrite: - check if a file is writablefileexec: - check if a file is executablefileowner: - check if a file is owned by the userfilegroup: - check if a file is owned by the groupfileempty: - check if a file is emptyfilesize: - check if a file is larger than 0 bytesfiletype: - check the type of a filefileperm: - check the permissions of a filefileage: - check the age of a filefilecontent: - check the content of a filefilecontentregex: - check the content of a file with a regexfilecontentregexcase: - check the content of a file with a case insensitive regexfilecontentregexword: - check the content of a file with a whole word regexfilecontentregexwordcase: - check the content of a file with a whole word case insensitive regexfilecontentregexwordlinenum: - check the content of a file with a whole word regex and line numberfilecontentregexwordcaselinenum: - check the content of a file with a whole word case insensitive regex and line numberfilecontentregexwordlinenumfile: - check the content of a file with a whole word regex and line number and file namefilecontentregexwordcaselinenumfile: - check the content of a file with a whole word case insensitive regex and line number and file namefilecontentregexwordlinenumfilecount: - check the content of a file with a whole word regex and line number and file name and countfilecontentregexwordcaselinenumfilecount: - check the content of a file with a whole word case insensitive regex and line number and file name and countfilecontentregexwordlinenumfilecounterr: - check the content of a file with a whole word regex and line number and file name and count and error messagefilecontentregexwordcaselinenumfilecounterr: - check the content of a file with a whole word case insensitive regex and line number and file name and count and error messagefilecontentregexwordlinenumfilecounterrex: - check the content of a file with a whole word regex and line number and file name and count and error message and exitfilecontentregexwordcaselinenumfilecounterrex: - check the content of a file with a whole word case insensitive regex and line number and file name and count and error message and exitwhilecond: - while loop with a specified conditionbreak: - break statement to exit a loop or switch statementcontinue: - continue statement to skip the rest of a loop and start the next iterationsleep: - pause the script for a specified number of secondsawk: - AWK one-liner for text processingsed: - SED one-liner for text processingtail: - display the last part of a filehead: - display the first part of a filesort: - sort lines of text filesuniq: - report or filter out repeated lines in a filecut: - remove sections from each line of a filepaste: - merge lines of filesawkscript: - AWK script templatesedscript: - SED script templategrepcolor: - search for a pattern in a file with colorgreplinenum: - search for a pattern in a file with line numbergrepword: - search for a pattern in a file as a whole wordgrepwordlinenum: - search for a pattern in a file as a whole word with line numbergrepwordlinenumfile: - search for a pattern in a file as a whole word with line number and file namegrepwordlinenumfilecount: - search for a pattern in a file as a whole word with line number and file name and countgrepwordlinenumfilecounterrex: - search for a pattern in a file as a whole word with line number and file name and count and error messagegrepwordlinenumfilecounterrexexit: - search for a pattern in a file as a whole word with line number and file name and count and error message and exitgrepwordlinenumfilecounterrexexitcase: - search for a pattern in a file as a whole word with line number and file name and count and error message and exit and case insensitiveforfile: - loop through files in a directorycasepat: - case statement with a specific patternselect: - create a select menu in a scriptfnparam: - function with parameters and default valuesifempty: - if statement for checking if a variable is null or an empty stringuntilcond: - until loop with a specified conditioncasemulti: - case statement with multiple patternsloopexec: - execute a command in a loop for each element in a collectioniffileexists: - if statement for checking if a file existsifdirexists: - if statement for checking if a directory existsifcommandexists: - if statement for checking if a command exists in the systemreadfile: - read lines from a file in a loopfnvarargs: - function with a variable number of argumentsforlineinfile: - loop through lines in a filegetscriptdir: - get the directory of the scriptcaseesac: - case statement with esacifinstalled: - check if a program is installedifroot: - check if a user has root privilegesoutputtofile: - redirecting output to a fileoutputerrorstofile: - redirecting output and errors to a fileifreadable: - if statement for checking if a file is readableifwritable: - if statement for checking if a file is writableifexecutable: - if statement for checking if a file is executableifsubstring: - if statement for checking if a string contains a substringifstartswith: - if statement for checking if a string starts with a prefixifendswith: - if statement for checking if a string ends with a suffixcommentblock: - useful comment blockreadvalidate: - read and validate user input
- Open Visual Studio Code
- Press
Ctrl+Pto open the Quick Open dialog - Type
ext install WaseemAkram.bashnsippetsto find the extension - Click the
Installbutton, then theEnablebutton
To use the snippets, open a Bash file, and start typing the name of a snippet. You'll see a dropdown list of suggestions. You can navigate through this list with Up and Down arrow keys. To insert a snippet, press Enter.
If you have suggestions for improving the BashSnippets, please open an issue or submit a pull request.
MIT © Waseem Akram
If you like this extension, you can support me by:
- Star this repository on GitHub
- Follow me on GitHub
- Support me on Patreon
- Follow me on Facebook
- Follow me on Instagram
- Your support is greatly appreciated! 🙏
Enjoy!