terminal

Escaping characters on the command line by Joseph Palumbo

While doing some housekeeping on my computer I ran into a situation where I wanted to delete all files that had a (1) in the name.

I started by listing all files that ended in .jpg

$ ls *.jpg
Screenshot 2019-10-07 13.50.50.jpg

I thought I could delete those files using basically the same syntax on the command line, but this is what I got when I tested it out.

Screenshot 2019-10-07 13.53.37.jpg

After Googling around I found this article on apple.stackexchange.com that helped me figure it out.

You can use the \ to escape characters on the command line, like this:

$ ls *\(1\).jpg
Screenshot 2019-10-07 13.56.02.jpg

Which lead to this solution:

Screenshot 2019-10-07 13.58.09.jpg

Simple Python Script To Search Wikipedia From The Command Line by Joseph Palumbo

If you’re like me, you don’t like to take your fingers off the keyboard. And if, like me, you’re a keyboard cowboy, you probably do a lot of work from the command line.

I’m always looking for ways to increase my productivity by adding more tools and functionality to my command line. So here’s a very simply python script using Selenium to search Wikipedia from CLI.

from selenium import webdriver
from sys import argv # Include file to upload
import sys

# unpacks the arguments passed on the command line
script = argv[0]

# joins multiple strings into one to create search_term
search_term = ' '.join(sys.argv[1:])

# test is variable is set
try:
    search_term
except NameError:
    print 'Please enter search term'
else: 
    browser = webdriver.Firefox()
    browser.get('https://www.wikipedia.org')
    browser.find_element_by_id('searchInput').send_keys(search_term)
    # content = driver.find_element_by_css_selector('p.content')
    browser.find_element_by_css_selector('button.pure-button').click()

Once you have this you need to crease a bash alias to be able to access it easily. I created the following:

alias wiki='python /Users/palumbo/code/tools/search_wikipedia.py'

Now anytime I want to look up something in Wikipedia, I just need to type wiki <search term> into my terminal and it brings up a new Firefox window with the wikipedia page for that term.

Finder Tags and Terminal by Joseph Palumbo

As I’m focusing on organizing and decluttering my digital life, I’ve started using the MacOS tag feature introduced back in Mavericks. It’s a powerful tool that can be used to create some simple, elegant, and scalable solution to folder and file organization.

The problem is that I use Terminal at least half the time to work with my folders and files and Apple does not provide an out-of-the-box solution for adding/removing tags from CLI. So say ‘hello’ to tag, a fantastic solution working with tags from MacOS Terminal.

Read More

My Brew Packages by Joseph Palumbo

If you're a hardcore MacOS (Mac OS X) user, than you no doubt know about Brew. Here is a list of the Brew packages I install almost immediately and what they do. 

But first, a few useful commands that might come in handy if you're not familiar with using Brew. 

Command Purpose
brew search [package] Lists all available forumla (aka packages). Additionally if you want to get further information about that package before installing it, add the package name to the command and it will detail relevant information like version number, dependencies, etc.
brew list Shows all of your installed packages.
brew install [package] Installs the specified package.

And here are some of the Brew packages that I find indispensable. 

tmux - Terminal multiplexer. Like screen, but way better

jq - Lightweight and flexible command-line JSON processor. Great for cleaning up messy and unreadable JSON output from scripts. 

awscli - The official AWS command-line interface. Don't bother trying to install the AWS CLI using the instructions found in AWS' documentation, the brew install is so much easier and organized. 

htop - The description for this package simply reads, "Improved top (interactive process viewer)", but I don't think that does it justice. If you need to find out what's running and utilizing resources on your computer, htop is second to none in this department. 

neofetch - Fast, highly customizable system info script. In short, if you need some quick info about. your system, install and run neofetch for an output like the one below. 

Screenshot 2018-08-14 09.26.35.jpg

python3 - MacOS ships with 2.7.X, but if you need to build or run something using Python3, Brew is the fasted and easiest way to install it on your Mac. 

tree - If you need a visual representation of a file or directory structure, tree is the perfect package for you. It displays directories as "trees" with an optional color output. It can be a littler verbose, but that's not always a bad thing. 

Screenshot 2018-08-14 09.33.35.jpg

tag - Manipulate and query tags on MacOS files.