Tuesday, February 19, 2019

Replacing text using sed on OSX

Yet another reminder post for my self.

One again is bumped into the error message

sed: 1: "test.txt": undefined label 'est.txt'

when trying to replace text in a file using sed. When using sed on OSX to replace text in files, using -i, the BSD variant of sed on OSX requires an extension parameter, where a copy of the original file saved.

The syntax is as following

sed -i '.bak' 's/before/after' file.txt

If you are sure of what you are doing you can leave the extension parameter empty and not having a backup.

sed -i '' 's/before/after' file.txt

As a reference, here is the syntax for the GNU variant, ie. Ubuntu and friends

sed -i 's/before/after' file.txt

Tuesday, December 22, 2015

Screenshots in OSX

This is mostly for my own convenience, since I always forget the screenshot key combinations for doing the various kinds of screenshots you can do in OSX.

  • Command + Shift + 3 : Take screenshot of the whole screen
  • Command + Shift + 4 : Take screenshot of a part of the screen
  • Command + Shift + 4 : Press Space and select window to take screenshot of
The command for taking a screenshot of a window also works on open menus.

Appels official documentation: https://support.apple.com/en-us/HT201361

Make Alt + left/right work in iTerm2

I recently got a new harddrive, SSD!!!! So I made the decision to wipe the slate and did a clean install. But as always not every thing worked as before, as always. One of the most annoying things was that Alt + left arrow did not jump one word to the left and vide versa for Alt + right arrow. This is OSX default behaviour, on Linux it is Ctrl + arrow keys.

Anyway, to solve this you need to change what iTerm sends when you hit the key combination. Quickest way is to change set keys shortcuts for the default profile to "xterm Defaults"
Next you need to set the correct key bindings in your .inputrc, .bashrc etc. The file depends on how you set up your system. I cannot remember what file is standard on OSX, but i have my config stuff in a .bash_profile to avoid polluting the system more the needed. So i put the following two lines in my .bash_profile

bind '"\033[1;9D": backward-word'
bind '"\033[1;9C": forward-word'

Reload your config file or open a new terminal and I have Alt + arrow keys back working.

Have a look at http://superuser.com/questions/357355/how-can-i-get-controlleft-arrow-to-go-back-one-word-in-iterm2 also.

Wednesday, August 12, 2015

Spotify web player keyboard shortcuts

It seems that the keyboard shortcuts for the Spotify web player are different based on OS and browser!!! And it looks like they tend to change a bit over time!! Thank you Spotify.

These work on OSX with Chrome (I am on a danish keyboard, not sure if this have anything to say)

Space - Play/Pause
Shift+Right arrow - Next track
Shift+Left arrow - Previous track
Shift+Ctrl+Right arrow - Forward in track approx. 15 sec
Shift+Ctrl+Right arrow - Backwards in track approx. 15 sec
Ctrl+Alt+s - Open search
Ctrl+Alt+Up arrow - Increase volume (not above system volume)
Ctrl+Alt+Down arrow - Decrease volume

Any I missed??

UPDATE

You need to have focus i the actual player for the shortcuts to work. So you need to click in the right side player for the keyboard shortcuts to work.

Tuesday, April 1, 2014

No DNS search domain for SSH after Mavericks upgrade

I often access a lot of server via SSH that all resides on the same domain. So I have set up a the as a search domain. Since I am on OSX I have do do this via the Network preference GUI. To add a search domain edit the connection, hit the DNS tab and a  the domain you want to autocomplete from. This will add the search domain to your resolve.conf, that is automatically generated on OSX. If you are on other *NIX systems, just edit your resolve.conf and add

search example.org

This will, after reload, enable you to ssh to a host under the search domain without specifying the full hostname, ie.

$ ssh root@host

will try to connect  to host.example.org.

For some reason this does not work out of the box on OSX after the Lion release. And it was again broken after I upgraded to Mavericks. Apparently the search domain is not used. Thank to Google I found this which helped my resolve the problem.

To fix the problem edit /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist and add the following key

<string>-AlwaysAppendSearchDomains</string>

to the array under ProgramArguments. After a restart of the DNS service by doing

$ sudo launchctl unload -w System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
$ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

SSH should complete hostnames from the search domain.