Snippets are one of my favorite parts of programming. The shear endless depth of command line tricks and customizations is so exciting! Here is a collection I maintain for myself to comeback to.
Also navigable by list of snippet types here.
Silver Searcher, it's like grep but faster and easier -- 11.01.2020 %
$ ag -G .php 'the meaning of the universe'
Life on the command line means grepping for things on a daily basis. After doing this for a while I memorized so may flag like grep -n for line numbers -i for case-insensitive and even the . to specify file directory. Then I discovered silver searcher, not only was the name a call back to one of my favorite comic book heroes but, it basically did work just as well as grep without all the flags and seemingly faster. It is now my go-to command for searching files whether it be inside vim via :r !ag -G .php ‘something’ or from the cli. It even has different outputs depending on the situation, in the cli it opens a temp window to browse results like less when piping or in vim it outputs a more machine-readable chunk of text with file paths, line numbers, and a single line of code.
Search Pass from password -- 11.01.2020 %
$ pass list | ag aws
Being a CLI interface the UX of Pass fits amazingly into the rest of the shell ecosystem. Need can’t remember if you have a password for AWS saved, run this.
Bulk import into Pass -- 11.01.2020 %
$ passimport list.csv
Switching to Pass was not exactly a straightforward process. It lacks a built-in mass import feature and I was dealing with a few hundred passwords and as a programmer entering them manually was unthinkable. After looking around at several plugins for Pass nothing seemed simple enough so I wrote my open python script to handle the task. I later turned that script into an executable, run by this command, and pushed it to GitHub.
Copy password from Pass to the keyboard -- 11.01.2020 %
$ pass -c github
Switching to Pass, a CLI based password manager, was a big time saver for me. I was using Padlock, a minimalist open source electron based manager, but was wasting so much time waiting for the GUI to load up and entering my master password scrolling to the desired entry and clicking. I’m not a time-saving purist but it was downright annoying UX pattern. Now I don’t even have to leave the comfort of my keyboard.
See previous commit changes -- 11.01.2020 %
git log -p -2 or
git lg -p -2
Viewing previous changes was something I relied on a GUI’s for, like GitLab/Source-Tree, until I found this command! The -p stands for –patch and the -2 stands for last two commits.
Aws S3 Sync -- 11.01.2020 %
$ aws s3 sync --acl public-read --sse AES256 build/ s3://travisshears.com
Having the ability to send a site live with a single command is heaven and not a BASH script with a bunch of moving parts liable to break. This command takes me back to the old days when putting a site live meant an FTP upload command to a server letting Apache take care of the rest. This site, for example, is hosted in an AWS S3 bucket that is connected to AWS CloudFront.
lustforge - great blog post
AWS CloudFront invalidation Sync -- 11.01.2020 %
$ aws cloudfront create-invalidation --distribution-id E29OAXKYAP0NP8 --paths /work/
Pairing well with the sync is invalidating the CDN so that the live site is updated immediately with the S3 bucket. Like everything these days, there is a cost involved with this operation so if I’m not in a rush I often avoid it. Also you can reduce cost by using –paths only invalidating needed routes.
lustforge - great blog post
Pretty print JSON -- 11.01.2020 %
$ curl -X GET https://some.json.endpoint.com | python -m json.tool
Need to check a API request but stuck reading a garbled mess. Try pipeing the result to python json.tool