Skip to content

Instantly share code, notes, and snippets.

View petergi's full-sized avatar
💭
Just Busy Living On The Side Of A Square

Peter Giannopoulos petergi

💭
Just Busy Living On The Side Of A Square
View GitHub Profile
```bash
# To ssh via pem file (which normally needs 0600 permissions):
ssh -i <pemfile> <user>@<host>
# To connect on a non-standard port:
ssh -p <port> <user>@<host>
# To connect and forward the authentication agent:
ssh -A <user>@<host>

As configured in tmux.conf

set-option -g default-command "tmux-shell-wrapper"

# Make shift+arrows, ctrl+arrows etc work in Vim.
set -g xterm-keys on

# See if this fixes slow ESC issues.
# http://unix.stackexchange.com/questions/23138/esc-key-causes-a-small-delay-in-terminal-due-to-its-alt-behavior

These were valid in OSX Leopard. I haven't updated them since

Key Function
Command+A Selects all items in the active window (icon view), all items in the column (column view), or all items in the list (cover flow view)
Command+C Copies selected items
Command+D Duplicates the selected item(s)
Command+E Ejects the selected volume
Command+F Displays the Find dialog
Command+H

Global

  • :help keyword - open help for keyword
  • :saveas file - save file as
  • :close - close current pane
  • K - open man page for word under the cursor

Exiting

Older Macs:

# Enable (Default)
sudo nvram BootAudio=%01

# Disable
sudo nvram BootAudio=%00

From 2016 models on:

@petergi
petergi / Reading a file in the shell a single line at a time
Last active March 25, 2023 20:57
Simple examples of reading a file in the shell one line at a time.
cat file.txt | while read line || [[ -n $line ]];
do
printf '%s\n' "$line" # do something with $line here
done
#!/usr/bin/env bash
# This is a bash script template in order to help you quick start any script.
# It contains some sensible defaults, you can learn more by visiting:
# https://google.github.io/styleguide/shell.xml
#
# This option will make the script exit when there is an error
set -o errexit

To find the length of a string use the # symbol

echo "${#MY_STRING}" 

Converting strings to Array

MY_ARR=($MY_STRING)

Curl cheatsheet

Options

-o <file>    # --output: write to file
-u user:pass # --user: Authentication
-v           # --verbose
-vv          # Even more verbose
-s           # --silent
#!/usr/bin/env bash
# Check ownership and permissions of a file
function checkPermissions() {
file="$1"
expectedOwner="$2"
expectedPermissions="$3"
expectedUid=`id -u "$expectedOwner"`