Mirror Displays β€” A Mac app and command-line tool for fiddling with display mirroring

MirrorDisplays a simple application that toggles between mirrored and extended desktop modes. It’s the easiest way to turn on, or turn off display mirroring.

Also comes with a (separately installable) CLI tool which makes this pretty interesting

The command line tool is good for giving shell-scripts the power to control display mirroring and opens up the possibility of controlling mirroring remotely over ssh.

usage: mirror [option]    Only the first option passed will be applied
  -h            Print this usage and exit.
  -t            Toggle mirroring (default behavior)
  -on           Turn Mirroring On
  -off          Turn Mirroring Off
  -q            Query the Mirroring state and write "on" or "off" to stdout
  -l A B        Makes display at index B mirror the display at index A

Unfortunately not installable using Homebrew, so you’ll have to get the app from the GitHub releases page. You’ll also have to explicitly allow the mirror CLI tool to be opened through the Security & Privacy

mirror-displays (GitHub) →
Mirror Displays Introductory Post →

πŸ’‘ If you’re using a MacBook with only one external display connected you might not need this app, and can use the CMD+F1 shortcut to toggle display mirroring/extending.

Send mail with Exim from the CLI

I needed to test whether mail relaying worked with Exim or not. To do so I used this command:

exim -v [email protected]

After this type in your mail contents as shown below and hit CTRL+D afterwards to send it:

From:[email protected]
Subject: Hello From the CLI
This is a test from the CLI

It’s also possible to use a one-liner:

echo -e "From:[email protected]\nSubject: Hello From the CLI\nThis is a test from the CLI" | exim -v [email protected]

You’ll see the raw output appear on screen, and should see a 250 status code near the end if all went well.

Did this help you out? Like what you see?
Thank me with a coffee.

I don't do this for profit but a small one-time donation would surely put a smile on my face. Thanks!

β˜•οΈ Buy me a Coffee (€3)

To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.

Beware when base64-encoding on the CLI using echo

Recently I needed to base64-encode a string. To do this I turned to the CLI and piped the output of echo to base64.

# Don't use! Correct command further down this post.
$ echo 'test' | base64
dGVzdAo=

Although the output looks quite good, things didn’t quite work out when using the string: it failed when used in an implementation.

Tracking down the issue I worked my way back and decided to double check the base64-encoded string (dGVzdAo=) for its correctness. Using PHP I re-encoded the input and voila:

$ php -r "echo base64_encode('test');"
dGVzdA==

That’s different output … and it’s also to correct result. But how come? Is base64 on the CLI wrong?

~

Don’t worry, base64 on the CLI works fine. The problem we’re having here is further upstream, namely with the use of echo. By default echo will append a newline to its output, and that’s why base64 is returning an unexpected result.

Thankfully echo has a -n switch to suppress the trailing newline. By using that, things work as expected:

# Add -n to echo to prevent it from adding a newline
$ echo -n 'test' | base64
dGVzdA==

Let this post act as a note to my future self … πŸ˜…

~

Did this help you out? Like what you see?
Thank me with a coffee.

I don't do this for profit but a small one-time donation would surely put a smile on my face. Thanks!

β˜•οΈ Buy me a Coffee (€3)

To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.

bandwhich – Terminal bandwidth utilization tool

bandwhich sniffs a given network interface and records IP packet size, cross referencing it with the /proc filesystem on linux or lsof on macOS. It is responsive to the terminal window size, displaying less info if there is no room for it. It will also attempt to resolve ips to their host name in the background using reverse DNS on a best effort basis.

bandwhich – Terminal bandwidth utilization tool →

Via @atog

Open your React Native’s Xcode project file from the CLI with xed

For a long time I always used the open command to open the Xcode project file contained inside React Native Projects.

bramus in ~/repos/projects/react-native/example
$ open ios/Example.xcodeproj

It wasn’t until I recently started a new React Native project that react-native init afterwards informed me to use xed instead.

The xed tool launches the Xcode application and opens the given documents, or opens a new untitled document, optionally with the contents of standard in.

With xed you don’t need to know the name of the project file. Just pass in the ios folder as an argument and it will handle things for you:

bramus in ~/repos/projects/react-native/example
$ xed ios

πŸ’β€β™‚οΈ xed handles both workspaces (.xcworkspace) and regular project files (.xcodeproj) so no worries there πŸ™‚

Furthermore, if you don’t want to remember yet another extra command, you can always add it as a script to your package.json:

{
	…
	"scripts": {
		…
		"xcode": "xed ios"
	},
	…
}
Did this help you out? Like what you see?
Thank me with a coffee.

I don't do this for profit but a small one-time donation would surely put a smile on my face. Thanks!

β˜•οΈ Buy me a Coffee (€3)

To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.

Bash/Shell Autocompletion for Composer

The other day I opened up a PHP project that I hadn’t worked on in a while. No longer remembering which Composer Scripts I had defined for it, I needed to take a peek inside composer.json to see which ones were available to me. Then it hit me: why is there no autocompletion for composer available?

Googling around a bit I eventually turned to creating my own Bash completion script for Composer. After installing it, it will autocomplete composer commands for you:

$ composer in[TAB][TAB]
info     init     install

πŸ’‘ Want to build your own bash completion script? This very good tutorial has got you covered.

The code builds further upon this earlier work by Rob Allen. Key area where it differs from Rob’s work is that composer-autocomplete also provides autocompletion for composer run-script, listing which Composer Scripts are available to you (as I initially wanted).

{
    "name": "bramus/example-php-package",
    "description": "Example PHP Package",
    "type": "library",
    "license": "MIT",
    …
    "scripts": {
        "test": "./vendor/bin/phpunit --colors=always",
        "lint": "php-cs-fixer fix --diff --dry-run --ansi",
        "fix": "php-cs-fixer fix"
    }
}
$ composer run-script [TAB][TAB]
fix   lint  test

Bash/Shell Autocompletion for Composer →

Did this help you out? Like what you see?
Thank me with a coffee.

I don't do this for profit but a small one-time donation would surely put a smile on my face. Thanks!

β˜•οΈ Buy me a Coffee (€3)

To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.

Instagram Terminal Feed

Forget about that Instagram for Windows 95, and go for the real deal: Instagram on the CLI:

Sometimes checking your instagram during work is kind of strange, so why not check your instagram inside your terminal? OK… I know checking this during work is still strange… πŸ˜‘ To be honest, I did this just for pure fun.

A color mode is also available.

Instagram Terminal Feed →