⑨ lab ≡ ByteLabs

Darwin/Setup

My setup on Darwin, it is weird, only for me, not recommended…

⑨ lab ≡ ⑨ Darwin Setup…

term% @{ramfs ; cd /tmp ; hget https://9lab.org/vid/plan9/NeinFront.mp4 > NeinFront.mp4 && treason NeinFront.mp4}

Overview

Applied after a clean install of MacOS Monterey. The objective is to use a minimal set of applications and changes to be productive.

General Setup

% mkdir $HOME/bin
% mkdir $HOME/src
% mkdir $HOME/lib
% echo 'path=($HOME/bin $path)' >> $HOME/.zshrc

System Preferences

Mission Control

Uncheck Automatically rearrange Spaces based on most recent use.

Accessibility

Turn on three finger dragging.

Xcode

Download latest version of Xcode from:

https://developer.apple.com/download/more/

…bypassing the app store.

TextEdit

To open UNTITLED file instead of the Open Dialogue:

; defaults write com.apple.TextEdit NSShowAppCentricOpenPanelInsteadOfUntitledFile -bool false

Screenshots

; mkdir -p $HOME/Pictures/Screenshots
; defaults write com.apple.screencapture location $HOME/Pictures/Screenshots
; killall SystemUIServer

Remote Desktop Client

The latest Beta of the remote desktop client is available here:

https://aka.ms/rdmacbeta

…avoiding the Mac App store.

Shell

Minimal shell configuration:

% cd $HOME
% >.zshrc ed - .zshrc <<EOT
i
path=(\$HOME/bin \$path)
.
w
EOT

Plan9Port

Prepare

% cat $HOME/lib/profile
# -- VARS  -------------------------------------
# -- default permissions for new files and folders
umask 077
# -- dump core files
# ulimit -c unlimited
# -- set prompt to term
prompt=('term% ' '	')
fn term%{ $* }
# -- set user
user=$USER
# -- set font
font=/mnt/font/Monaco/14a/font
# -- secstore
secstore=localhost
# -- set pager to nobs (aka cat)
PAGER=/usr/local/plan9/bin/nobs
MANPAGER=/usr/local/plan9/bin/nobs
VISUAL=/usr/local/plan9/bin/nobs
# -- set SHELL to rc
SHELL=/usr/local/plan9/bin/rc
# -- set EDITOR and GIT_EDITOR
EDITOR='open -e'
GIT_EDITOR=ed
# -- set tabstop to 2
tabstop=2
# -- GO SETTINGS (https://golang.org/cmd/go/#hdr-Environment_variables)
GOBIN=$HOME/bin
GOPATH=$HOME/lib/go
# -- HOMEBREW SETTINGS
HOMEBREW_NO_COLOR=1
HOMEBREW_NO_EMOJI=1
# -- tree command color settings
TREE_COLORS=''
LS_COLORS=''
# -- PATH -------------------------------------
paths=(`{cat /etc/paths} $HOME/bin .)
for(p in $paths) {
  if(! ~ $p $path) {
    path=($path $p)
  }
}

Install

% cd /usr/local
% sudo mkdir plan9
% sudo chgrp staff plan9
% sudo chmod g+w plan9
% git clone https://github.com/1g0rb0hm/plan9labs.git plan9 && cd plan9
% ./INSTALL

Configure

Make rc the default shell:

% sudo sh -c 'echo /usr/local/plan9/bin/rc >> /etc/shells'
% chsh -s /usr/local/plan9/bin/rc

Configure plumber:

% cat $HOME/lib/plumbing
# to update: cat $HOME/lib/plumbing | 9p write plumb/rules
editor = acme
include basic

Launch plumber:

% cat $HOME/Library/LaunchAgents/9lab.org.plumber.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>9lab.org.plumber</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/plan9/bin/plumber</string>
    <string>-f</string>
  </array>
  <key>EnvironmentVariables</key>
  <dict>
    <key>PLAN9</key>
    <string>/usr/local/plan9</string>
    <key>PATH</key>
    <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/plan9/bin</string>
  </dict>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
  <key>StandardOutPath</key>
  <string>/tmp/igor.plumber.out.log</string>
  <key>StandardErrorPath</key>
  <string>/tmp/igor.plumber.err.log</string>
</dict>
</plist>

% launchctl load -w $HOME/Library/LaunchAgents/9lab.org.plumber.plist
% launchctl list | grep '9lab.org.plumber'

Run multiple Acme instances:

#!/usr/bin/env rc
# run acme instance in new namespace (enables multiple instances)
flag e+
NAMESPACE=`{namespace}^-^'acme'^-$pid
mkdir -p `{namespace}
acme $*
rm -rf `{namespace}

Secstore, factotum, ipso:

% secstore=localhost
% secstored
% secuser -v $user
...
% security add-generic-password -a $user -s pass -w 'S3cr3t'
% cd /tmp
% secstore -g factotum
% echo 'key proto=apop dom=x.com user=ehg !password=hi' >> factotum
% secstore -p factotum
% echo 'Secret Passwords' >> pass
% secstore -p  pass
...
% ipso
...
CATEGORY    NAME       LOGIN        PASSWORD   URL
Account     NeinFront  N31nN31n999  9999N31n   random pass entry
...

Launch secstored:

% cat $HOME/Library/LaunchAgents/9lab.org.secstored.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>9lab.org.secstored</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/plan9/bin/secstored</string>
    <string>-v</string>
  </array>
  <key>EnvironmentVariables</key>
  <dict>
    <key>PLAN9</key>
    <string>/usr/local/plan9</string>
    <key>PATH</key>
    <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/plan9/bin</string>
  </dict>
  <key>RunAtLoad</key>
  <true/>
  <key>StandardOutPath</key>
  <string>/tmp/igor.secstored.out.log</string>
  <key>StandardErrorPath</key>
  <string>/tmp/igor.secstored.err.log</string>
</dict>
</plist>

% launchctl load -w $HOME/Library/LaunchAgents/9lab.org.secstored.plist
% launchctl list | grep '9lab.org.secstored'

Launch factotum:

% cat $HOME/Library/LaunchAgents/9lab.org.factotum.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>9lab.org.factotum</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/plan9/bin/factotum</string>
    <string>-n</string>
  </array>
  <key>EnvironmentVariables</key>
  <dict>
    <key>PLAN9</key>
    <string>/usr/local/plan9</string>
    <key>PATH</key>
    <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/plan9/bin</string>
  </dict>
  <key>RunAtLoad</key>
  <true/>
  <key>StandardOutPath</key>
  <string>/tmp/igor.factotum.out.log</string>
  <key>StandardErrorPath</key>
  <string>/tmp/igor.factotum.err.log</string>
</dict>
</plist>

% launchctl load -w $HOME/Library/LaunchAgents/9lab.org.factotum.plist
% launchctl list | grep '9lab.org.factotum'

Choose password using fuzzy matching:

% cat $HOME/bin/pass.choose
#!/usr/local/plan9/bin/rc -l
rfork e
ifs='
'
# security add-generic-password -a $user -s pass -w 'S3cr3t'
# security find-generic-password -a $user -s pass -w
pwd=`{/usr/bin/security find-generic-password -a $user -s pass -w}
sec=(`{echo $pwd | /usr/local/plan9/bin/secstore -i -G pass})
sel=`{ @{for(s in $sec){ echo $s }} | awk '{$4="";print}' | choose -i}
@{for(s in $sec){ echo $s }} | awk 'NR=='^$sel^'+1  {printf("%s",$4)}' | $home/bin/spbcopy

Skhd

Install

% cd $HOME/src
% git clone https://github.com/koekeishiya/skhd.git && cd skhd
% make install
% cp bin/skhd $HOME/bin

Configure

% cat $HOME/.config/skhd/skhdrc
.blacklist [
  "drawterm"
]

# -------------------------------------------------------------------

# -- `⌘ ↩`       -> Plan9: 9term + rc
cmd - return  : cd $HOME && /usr/local/plan9/bin/9.rc 9term -f /mnt/font/Monaco/14a/font rc -l

# -- `⌘ ⌥ ↩`     -> Terminal
cmd + alt - return  : cd $HOME &&  /usr/local/plan9/bin/9.rc open -n -a Terminal

# -- `⌘ shift ↩` -> Drawterm
cmd + shift - return : open -n -a $HOME/bin/drawterm-metal.app

# -------------------------------------------------------------------

# -- `⌘ ⌥ 9`  -> Plan9: ACME Editor
cmd + alt - 9 : cd $HOME && /usr/local/plan9/bin/9.rc acme -c2 -a -i  -f /mnt/font/Monaco/14a/font -F /mnt/font/Monaco/14a/font

# -- `⌘ ⌥ a`  -> Plan9: ACME Editor in NEW Namespace
cmd + alt - a : cd $HOME && /usr/local/plan9/bin/9.rc acme.ns -c2 -a -i -f /mnt/font/Monaco/14a/font -F /mnt/font/Monaco/14a/font

# -- `⌘ ⌥ 8`  -> Plan9: Sam Editor
cmd + alt - 8 : cd $HOME && /usr/local/plan9/bin/9.rc sam -a

# -- `⌘ ⌥ b`  -> Browser (URL taken from pbpaste)
cmd + alt - b : pbpaste | awk '{print "\""$0"\""}' | xargs $HOME/bin/Safari

Open Safari with URL from clipboard:

% cat $HOME/bin/Safari
#!/usr/local/plan9/bin/rc
osascript -e 'tell application "Safari"
    make new document
    set URL of document 1 to "'^$1^'"
    activate
end tell'

Launch

% cat $HOME/Library/LaunchAgents/9lab.org.skhd.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>9lab.org.skhd</string>
  <key>ProgramArguments</key>
  <array>
    <string>/Users/igor/bin/skhd</string>
  </array>
  <key>EnvironmentVariables</key>
  <dict>
    <key>PLAN9</key>
    <string>/usr/local/plan9</string>
    <key>PATH</key>
    <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/plan9/bin</string>
  </dict>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
  <key>StandardOutPath</key>
  <string>/tmp/igor.skhd.out.log</string>
  <key>StandardErrorPath</key>
  <string>/tmp/igor.skhd.err.log</string>
</dict>
</plist>

% launchctl load -w $HOME/Library/LaunchAgents/9lab.org.skhd.plist
% launchctl list | grep '9lab.org.skhd'

Brew

Install

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
% sudo xcode-select -switch /Applications/Xcode.app
% xcode-select -p
/Applications/Xcode.app/Contents/Developer
% brew install fd rg tmux choose-gui

Pass

Install

% brew install pass pinentry-mac

Configure

% cat .gnupg/gpg-agent.conf 
pinentry-program /usr/local/bin/pinentry-mac
default-cache-ttl 86400
max-cache-ttl 86400

To quickly access key passwords (e.g. for work) using spotlight use AppleScript and export it as an Application:

do shell script "eval `/usr/libexec/path_helper -s`; pass show -c work"

Drawterm

Install

Build Metal and Cocoa variants of Drawterm:

% brew install portaudio
% cd $HOME/src
% git clone https://github.com/1g0rb0hm/drawterm.git && cd drawterm
% CONF=osx-metal make -j4
% cp drawterm gui-cocoa/drawterm.app/
% cp -r gui-cocoa/drawterm.app $HOME/bin/drawterm-metal.app
% make clean
% CONF=osx-cocoa make -j4
% cp drawterm gui-cocoa/drawterm.app/
% cp -r gui-cocoa/drawterm.app $HOME/bin/drawterm-cocoa.app

Clipboard History

Install Maccpy as a light-weight solution for a clipboard manager.

Development

To use the command-line build and debug tools successfully (i.e. without XCode) the following is required:

% sudo DevToolsSecurity -enable
Developer mode is now enabled
% sudo dseditgroup -o edit -a igor -t user _developer

#Plan9Port #Acme #Darwin #Dev