"The real power of the computer is its ability to do the work for you. To get it to do that, we use the power of the shell to automate things. We write shell scripts." - random site
As these are shell scripts, they're meant to be run in the shell (specifically a Unix shell). I'm using Bash on a Mac, so a few things may work differently for you (I'll remark on those differences if I can catch them). I don't think I have any 'bashims" in my scripts (i.e. features not defined by POSIX, which are specific to the Bash shell), so at least that shouldn't be an issue. Update: I'm also using these on Arch Linux now, so they should work for you wherever you may be.
To start, I suggest creating a directory titled .scripts in your home folder, noteably including the . prefix so to not visually clutter up your working space (I've learned from my mistakes). This is where you'll be keeping all of the shell scripts you write/save.
Next, you'll need to add this directory to your PATH. Essentially this gives you the ability to refer to any files within the directory simply by their name, even when you're working in a different directory (e.g. writing example vs something like ~/.scripts/example). To do this, edit your .bash_profile or .profile, which are located in your home directory, and insert this line: export PATH=$PATH:~/.scripts. Note: If you already have something similar, you can simply add :~/.scripts at the end of the line.
The last step (once you have the scripts in the proper directory, of course), is to execute the command chmod +x examplefor each file, thus making them executable. And that should be it!
hmm
- This one simply clears the screen and then calls
ls-- it's essentially a fidgeting command that I can call while I'm thinking about what to do next (hence the name).hmmis also shorter to write thanclear, which saves me a few milliseconds :P. (Note: ^L, aka CTRL L, clears the terminal screen as well, and can be used as an alternative toclear)
newcpp hello newcpp hello.cpp newjava hello newjava hello.java
- These scripts help bypass boilerplate code that wastes time and accelarates your impending carpal tunnel. Invoking the command opens your default editor/IDE with a new .cpp/.java file, already named and containing a few lines of code. The script checks whether you've included the extension for the file in your argument, so there's no need to write anything besides your desired file name.
- (Compatability note: these scripts use the
opencommand, which is unique to MacOS -- it just uses the default program to open a file based on its extension. The Linux alternative toopenisxdg-open. For other Unix systems, changingopento your desired text editor, e.g.nano, should do the trick.).
run hello.cpp
-
(requires: gcc/g++)
-
Short and sweet -- this script compiles a .cpp file with
g++(creating a.out) and runs the resulting out file.
mp3 https://www.youtube.com/watch?v=dQw4w9WgXcQ mp3 --crop 1:00 2:08 https://youtu.be/DljBMflGdek #only downloads a specified portion of the audio
-
(requires: youtube-dl)
-
I cannot recommend
youtube-dlenough, both as an alternative to suspicious YouTube2MP3 websites, and to streaming services such as Spotify. Callingmp3 <url>downloads the requested file to your current directory. If you're using iTunes or a similar music player, you have to first open the file in the player manually in order for it to show up in your music library. For me, this process often looks like this:
- Call
mp3 <url>in my home directory (for as many songs as necessary) open *.mp3(at this point the songs will successfully be in iTunes)mv *.mp3 ~/Downloads(or to wherever you store your music files)- Next time you play a song you moved, iTunes may or may not give you an error message claiming it cannot find the file (since you moved it to a new directory). Simply follow the prompts it gives you, locate the erroneous file in Finder, and the rest will be found automatically. This is, of course, a horrible solution, but the important thing is that you have the file readily accessible on your computer.
- Optionally, you can add points 2. and 3. to the script, but I prefer not to have iTunes open every time I download a file.
Suggestion: If you only need a snippet of some audio, rather than the entire file, download Audio Hijack, a great program with an indefinite free trial that allows you to record the audio directly from your computer.
Suggestion #2: Play your music in style with my command-line music player, teapot :P
fuck mylife
- Do you have a million shell scripts with stupid names? Do you find yourself forgetting which one is which and what they're supposed to do? Voila, I present to you
fuck, which simply opens your script of choice in read-only mode, allowing you to inspect its contents and hopefully remember its purpose. If only I could add man pages for my scripts... - Note: change the path in the script to the path of your shell scripts directory
fishme "endl" #prints out all instances of "endl" in files in the current directory
- The rich man's ctrl-f -- you'll now be able to search for instances of a string in files in your directory. This was inspired by the workflow of Andreas Kling in his SerenityOS videos.
- Why is it called
fishme? Hey Siri, fish me an explanation for this question.
nuke #recursively removes all instances of .DS_Store in a directory
- Fuck .DS_Store, all my homies hate .DS_Store
repl c++ #starts a read-eval-print loop for c++ (also available: c, c++, java)
- Sometimes you just want to test out a certain facet of a language. A read-eval-print loop lets you do that without the hassle of boilerplate code and without having to repeatedly recompile.
- The script is really just compiling your program and displaying the result every time you press enter, but the way it's set up makes it function like a repl environment. The compile time is near instantaneous after the first instruction you enter because of cache, so that's not an issue.
gack notes.ms # generates a notes.pdf
- This one's for all you
groffers out there. If you write a document withgroff(ms macros), calling this command on it will generate a PDF file with the same name. - (requires: groff, cupsfilter)
- Both of these are likely to be installed on your computer already, especially if you're on a Mac. That's why I'm using this instead of LaTeX!
- Note: for more information + a general workflow + vim stuffs, see my notes repo
server ~/Documents/cooldirectory32
- (requires: Python)
- Starts up a server on localhost, port 8080, with the files in the specified directory. Once you run it, navigate to
https://localhost:8080on your browser :)- If there's no
index.htmlalready in the directory, the script generates a default one before starting up the server.
- If there's no
- This is probably pretty useless on its own, but my goal is to use this as a building block for command line utilities that start up a GUI on your localhost upon launch. This was inspired by geohot's qira debugger.
wiki #Presents you with 10 random wikipedia articles to choose from
-
(requires: Python)
-
This script is actually written in Python, but since you can also do
chmod +xon Python scripts (and even drop the .py), I figured it was still relavant to include here. To use, simply callwikiand then enter the index of the article you want to read (or -1 for 10 new articles) -- it'll be opened in your default web browser. The articles are fetched from this Wikipedia API. -
(Compatability note: this script uses the
opencommand to open the article in your default browser. If you're not on MacOS you can change that toxdg-openor to the name of your desired browser)
russian privet droog, kak dela? #outputs russian transliteration: привет друг, как дела?
-
(requires: Python)
-
I got tired of having to search for sites with virtual Russian keyboards every time I wanted to transliterate babushka into бабушка. This script just takes English letters and turns them into their Russian counterparts (including some English diphthongs which exist as a single letter in Russian).
-
This isn't "correct" in any measurable way, and it's tuned towards how I tend to spell out words so you might want to change stuff around.
./lyrics linkin park - faint
-
(requires: Python, and the BeautifulSoup4 and requests modules )
-
Prints out the lyrics for a requested song (if you wanna read them normally I'd recommend piping the output into
less). Don't steal my API key.
intro #Does colorful stuffs
-
This one's just for fun; it prints out some colorful things as well as a random ASCII art character using
cowsay.
copy hello world im cool #copies "hello world im cool" to your clipboard cat myfile.txt | copy #copies contents of myfile.txt to your clipboard
-
(requires: Python)
-
This might only work on Mac, be ware.
record #yields OUT.mp4 record --mov #yields OUT.mov record name #yields name.mp4 record --mov name #yields name.mov (order doesn't matter)
-
(requires: ffmpeg)
-
Another indispensible tool in anyone's toolkit --
ffmpeg. If you've ever tried to record your screen on MacOS, then you've probably experieced the perils of QuickTime Player and .mov. Though I appreciate Apple providing a native screenrecorder, QuickTime is bulky, only works with files in .mov format (which happen to be huge and don't work well with YouTube), and is relatively featureless. Also, c'mon, having that QuickTime icon in your Dock while recording makes you look like an amateur! Lol. -
With
record, you can call the command whenever you're ready to start, and enter q or ^C to finish recording. The resulting file will be titled OUT.mp4, or something similar if you provided some arguments. If you've accidentally messed up the video format, you can convert from .mov to .mp4 (or vice versa) when finished by invoking this command:ffmpeg -i input.mov output.mp4. -
(Compatability note: the arguments within this script strongly depend on your OS and even your specific setup -- make sure to visit this site for info on how to properly configure for your system. I also provided a commented command that would work on Linux.)
-
Note 2: Check the script for an equivalent command that works on Linux (it's commented out)
concatv #concatenates all .mp4 files in directory concatv vid1.mp4 vid2.mp4 vid3.mp4 #concatenates .mp4 files listed as arguments
-
(requires: ffmpeg)
-
If you ever have multiple video files which you'd like to stitch together into one video, this script is the one to use. Invoking it will result in a file called final.mp4. Be ware that the order in which you list your arguments matters (they will be concatenated in that order). Note: only meant to work for .mp4 files, but can very easily be changed to support any filetype supported by
ffmpeg. Note 2: Apparently the video files are required to be in the same aspect ratio and size in order for this to work. In order to not run into issues with this, just record your full screen or assure that the videos are the same size. Hopefully I can find a fix for this.
delayaudiov #Asks for input video, seconds to delay by, and output file
-
(requires: ffmpeg)
-
If your audio and video are somehow out of sync (which has been happening to me a lot recently), you can try to remedy that with this script. If you don't know exactly how far the video lags behind the audio, you can keep delaying the audio by 1 second at a time until you're satisfied.
changevolumev #Asks for input video, decibels to change audio by (+/-), and output file
-
(requires: ffmpeg)
-
If your audio is either too quiet or too loud, you can adjust that with this script. Again, if you're unsure of exactly how much to raise/decrease the volume by, incrementally call this script with small changes until satisfied.
Preface: RMarkdown is awesome. If you're taking notes in a WYSIWYG editor, stop it! RMarkdown is a markup language, meaning you use it to specify what you want a document to look like/contain (yep, just like HTML... except HTML sucks). You're also free to use arbitrary bits of LaTeX or HTML anywhere in your note, and with pandoc it easily outputs to PDF or HTML. Did I mention the notes also look beautiful? Oh, and you can run code within the notes... nice. I'm not gonna be able to give a comprehensive tutorial on setting up, so check this out as a start.
note coolname #Creates a file named coolname.rmd in your notes directory with some prefilled information
- This just creates a new note, prefills some meta-data (such as the title, author name, date, and output file format). If you use this script change the following things: (1) the author name, (2) the directory your notes are created in. You might also want to change
vimto your preferred editor (or to$EDITOR).
render mynote.rmd #Compiles .rmd file to specified (in meta-data) output file format
-
Usually when people use RMarkdown they write it and compile it in RStudio. If you want to use something else, this is the command you can use to compile your note.
-
Note: If you want a keyboard shortcut for this in vim, I got u. Just add the following to your
.vimrcfile, or wherever you keep your config:autocmd FileType rmd map ,2 :!echo<space>"require(rmarkdown);<space>render('<c-r>%')"<space>\|<space>R<space>--vanilla<enter>- Now you can simply press
,2and the .rmd file will compile (don't forget to save your changes beforehand).
- Now you can simply press
Preface: Stuff is hard to set up sometimes. After installing Arch Linux a bunch of things were not working for me, so I had to cobble together imperfect but functional solutions (some are better than others, this backlight script is something from another planet).
- This is referring to the computer screen brightness, by the way.
su root #This script requires you to be root in order to execute it :D backlight up #Raises the backlight by 80 (out of 852, so that's roughly 10 executions to go from off to on) backlight down #Lowers the backlight by 80 backlight on #Maximizes brightness to 100% backlight off #Turns off screen completely (not recommended, as you'll have to turn it back on by typing without seeing anything lol) backlight dim #Lowers backlight to the dimmest possible brightness (but still visible).
- For some reason I couldn't bind my function keys to actually change my brightness. Maybe you're in the same situation. This is a workaround.
)*
Note: This will probably work in a similar way for you, but you might have to change
intel_backlighttoacpi_video, as well as change the numbers. Read this guide for more information.
- This is referring to the keyboard backlight
#You'll need to have sudoers access to use this light 2 #I believe this is the maximum brightness value light 1 #A nice medium light 0 #No keyboard backlight
- Again, if you can't seem to figure out any better solution you can use this. For more information, read this.
usbguide #Prints out a nice guide for mounting and unmounting a USB using the terminal
- Ah, yes, another missing functionality. This script doesn't actually mount the USB for you, but rather prints out a little guide to help you do it by hand.
screenshot #Saves screenshot in file named output.jpg
-
(requires: ffmpeg)
-
If you don't have any utility to take screenshots for you, this is a cheap alternative (cheap as in lacking in dependencies, not as in $$$, cause this is obviously free lols). "What if I don't want the terminal window to be in my screenshot?" you say... well this takes a second to execute so you have just enough time to somehow hide the window (or you can bind the script to execute when you hit a certain key, which gives me a good idea...).
-
Note: make sure to change the screen size to the dimensions of your screen

