Terminal Tools
Markdown to HTML conversion with pandoc
pandoc --metadata title="Markdown to HTML" -s -o markdown_output.html markdown_to_html.md
- to merge multiple markdown files into a single html, just add more after the first one in a varargs style
-
or
pandoc -s -o output.html input*.md
in glob style -s
tells pandoc to create a self-contained file (so it will contain <html></html> tags etc, rather than just generating a fragment)-o
output.html specifies that output.html will be the output file
FFmpeg
How to extract a frame/frames from a video source in Terminal
Example:
ffmpeg -ss 124 -i input.mp4 -frames:v 1 output.bmp
-
-i url (input)
input file url -
-ss position
- When used as an input option (before
-i
), seeks in this input file to position. Note that in most formats it is not possible to seek exactly, so ffmpeg will seek to the closest seek point before position. When transcoding and -accurate_seek is enabled (the default), this extra segment between the seek point and position will be decoded and discarded. When doing stream copy or when -noaccurate_seek is used, it will be preserved. - When used as an output option (before an output url), decodes but discards input until the timestamps reach position.
- When used as an input option (before
-
-frames[:stream_specifier] framecount (output,per-stream)
Stop writing to the stream after framecount frames.
The Cat's Story
head
— Cat’s Head
Read the top of a file. Add -n <number>
to specify the number of lines to read or -c <number>
for the number of bytes to read.
tail
— Cat’s tail
cat
— The Complete Cat
cloc
cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
More info at Github/AlDanial
brew install cloc
direnv
unclutter your .profile
Sources / More on direnv.net
Info
Store your environment variables that you only need in specific folders, in a dedicated .envrc
file. That file will be loaded when entering that folder and will be unloaded upon exiting.
This helps to keep your .zshrc
, .profile
, etc. free of only project-specifically used export
ed environment variables.
Usage
- Navigate to your target folder
- Create a
.envrc
file and move your folder-specific exports and setup here - Security mechanism: Allow the
.envrc
file. This only has to be done once.direnv allow
Install
Install using Homebrew:
brew install direnv
and add the following line at the end of your .zshrc
:
emulate zsh -c "$(direnv hook zsh)"
Compatibility with Powerlevel10k
When you use Powerlevel10k, you may have noticed a warning popping up when you open a new terminal and the opened directory contains a .envrc
file.
To avoid that, add the following to your .zshrc
file:
emulate zsh -c "$(direnv export zsh)"
## Regular Powerlevel10k setup
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
emulate zsh -c "$(direnv hook zsh)"
Source: GitHub user romkatv on issue romkatv/powerlevel10k#702
imagemagick
Install
brew install imagemagick
Use
convert <input-file> <output-file>
jq — Command-line JSON processor
jq can transform JSON in various ways, by selecting, iterating, reducing and otherwise mangling JSON documents.
Easiest:
# file.json:
# {
# "version": "1.0.0"
# }
cat file.json | jq ".version"
# prints: "1.0.0"
More complex:
This command will take an array of JSON objects as input and return the sum of their “price” fields
# file.json:
# {
# "Lightsaber": {
# "price": 1234
# },
# "Blaster": {
# "price": 321
# }
# }
cat file.json | jq 'map(.price) | add'
# prints 1555
smartmontools
Install
brew install smartmontools
Use
smartctl -a disk0
speedtest.net
Install
brew install speedtest-cli
Use
speedtest
thefuck
Magnificent app which corrects your previous console command.
Installation
Using Homebrew:
brew install thefuck
Add the following to your .bash_profile, .bashrc or .zshrc:
eval $(thefuck --alias)
and/or
eval $(thefuck --alias fix)
for the SFW version
Github
Find the project at github.com/nvbn/thefuck
Units
- Huge tool for unit conversion
- Download from https://www.gnu.org/software/units/
- How to install/upgrade → see
INSTALL
file
In short:
cd <directory>
./configure
make
sudo make install
Various Terminal Tools
tr
— translate characters
echo "Heeeello" | tr -s "e"
# prints: "Hello"
echo " He ll o " | tr -d " "
# prints: "Hello"
xargs
— construct argument list(s) and execute utility
Use:
echo "He ll o" | tr -s " " | xargs echo
# prints: Hello
youtube-dl
Install
brew install youtube-dl
Use
youtube-dl <url>
Allows to download not only from YouTube, but from a huge list of websites, including Vimeo, but also sites like the German Public Broadcast Media Libraries, ARD Mediathek, ZDF Mediathek and many more.