-
Using lnav to View Live DDEV Logs
https://lnav.org/ is a fantastic tool to work with log files. The SQL query functionality is a lot like https://github.com/multiprocessio/dsq, which also impresses.
My quick tip is that lnav can read from stdin. This means you can pipe content into it. Here’s how I monitor my ddev environment in realtime. Hooray for colors!
1ddev logs -f | lnav -qIf you haven’t explored lnav you’ll want to dive into the documentation a bit. It does a lot more than just give pretty colors to your log files / output. https://docs.lnav.org/en/v0.11.2/hotkeys.html is certainly worth bookmarking.
-
Monitoring APFS Drive Decryption Progress
I recently decided to [permanently] decrypt an APFS volume via Finder (Right click the drive, choose Decrypt).
There wasn’t any indication that it was actually working. After some web searches, I pieced together a one-liner to monitor the progress of the decryption operation. This will refresh every 60 seconds. If your setup is anything like mine this will be an exceptionally slow operation.
1watch -n 60 "diskutil apfs list | grep 'Decryption Progress'" -
Triggers in iTerm – Watching For Specific Strings
I was recently performing a git-add in patch mode ( git add -p ) as I normally do, and realized there were a few lines I needed to make sure I didn’t commit. These lines were sandwiched between other lines that I did want to commit, and there were hundreds of changes, so it was hard to spot them. I wondered if iTerm2 had a way of highlighting or alerting when a specific word shows up in the terminal. To my surprise I found a “Triggers” section under the “Profiles » Advanced” tab in the settings for the app. iTerm2 really can do everything!
-
Customizable Date variables in Keyboard Maestro
UPDATE: Though the solution below works well, I do recommend following the first commenter’s advice and using the ICUDateTime text tokens instead, which allow you to use any ICU date format, without having to invoke a shell script.
Sometimes you need a date and/or time variable in your Keyboard Maestro macros.
The easiestOne way I’ve found to do this is via an “Execute Shell Script” action. You’ll just use the date command and format as desired. -
Determining Your Most Used Commands in Terminal
I’m always looking to automate things using Alfred, Keyboard Maestro, Text Expander, and Python. I was curious which terminal commands I use most often, so I did some experimenting. Basically I wanted to know how many times I’ve executed each unique command ( ssh myserverx or ssh myservery, not just ssh). I started by piping the output of history to sort (to group), then to uniq (to count), then back to sort (to sort by the number of occurrences).
1history | sort | uniq -c | sort -n
1cat ~/.bash_history | sort | uniq -c | sort -n -
“755”-style permissions with ‘ls’
After a quick Google search for “ls permissions octal” I found a very handy alias to put in my .bashrc. Not only is it handy to see the OCTAL value of the permissions for each file/dir, it will undoubtedly help you more quickly recognize/interpret the normal ls -al output.
1alias lso="ls -alG | awk '{k=0;for(i=0;i<=8;i++)k+=((substr(\$1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(\" %0o \",k);print}'"
1234mycomp:~ adam$ lso755 drwxr-xr-x 15 adam staff 510 Dec 6 02:47 .vim644 -rw-r--r-- 1 adam staff 1136 Dec 18 16:55 .vim_mru_files600 -rw------- 1 adam staff 13665 Dec 18 16:56 .viminfo
1ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}' -
Automatically Stage All Deleted Files (Git)
Tab-completion is a really nice thing that we often take for granted. While working with Git I’ve found that it becomes inconvenient to stage (add for inclusion in the next commit) removed files using git rm path/to/my/file.php. Tab completion doesn’t work on paths that no longer exist, so you have to manually type the path to the deleted item. The following snippet automatically stages ALL removed files.
git ls-files -d -z | xargs -0 git rm --cached --quiet -
Automatically Change Links from Absolute to Relative
In this example I’m showing one way to quickly convert all a href and img src paths from absolute to relative. It’s quite a time saver, but I suggest committing your latest changes before trying anything here! If you aren’t using a version control system, make a backup somewhere… please! Note: Both of these commands are one-liners.
1234567#BSD Version (Mac):find . -path './.git' -prune -o -type f -exec sed -i '' -E "s/(href|src) *= *([\"'])(https?:\/\/)?(www\.)?mysite\.(org|com)\//\1=\2\//g" {} \;#GNU Version:find . -path './.git' -prune -o -type f -exec sed -i -r "s/(href|src) *= *([\"'])(https?:\/\/)?(www\.)?mysite\.(org|com)\//\1=\2\//g" {} \;#You may consider using {} +; instead of {} \;In the examples/results below, I tried to target most situations. You should see subtle differences between each example.
1234567891011121314151617181920212223-<a href="https://www.mysite.org/basic_skills">This is another link</a>+<a href="/basic_skills">This is another link</a>-<a href="https://www.mysite.org/basic_skills">This is another link</a>+<a href="/basic_skills">This is another link</a>-<a href="http://www.mysite.org/basic_skills">This is another link</a>+<a href="/basic_skills">This is another link</a>-<a href="http://mysite.org/basic_skills">This is another link</a>+<a href="/basic_skills">This is another link</a>-<a href="www.mysite.org/basic_skills">This link points to http://www.mysite.org/basic_skills</a>+<a href="/basic_skills">This link points to http://www.mysite.org/basic_skills</a>-<a href="mysite.org/basic_skills">This is another link</a>+<a href="/basic_skills">This is another link</a>-<a href="http://www.mysite.com/basic_skills">This is the last link</a>+<a href="/basic_skills">This is the last link</a>-<img src="https://www.mysite.org/testing123.jpg">+<img src="/testing123.jpg">