Lots of stuff. Working on refactoring

This commit is contained in:
Thomas Loven 2017-10-14 09:47:18 +02:00
parent 8230d22739
commit 1b5423997e
23 changed files with 620 additions and 12 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
fish/fishd.*

4
NAS_mounts/auto_nas Executable file
View File

@ -0,0 +1,4 @@
/Users/[[UNAME]]/mnt/music -fstype=smbfs ://[[USERNAME]]:[[PASSWORD]]@nas.loven/music
/Users/[[UNAME]]/mnt/video -fstype=smbfs ://[[USERNAME]]:[[PASSWORD]]@nas.loven/video
/Users/[[UNAME]]/mnt/photo -fstype=smbfs ://[[USERNAME]]:[[PASSWORD]]@nas.loven/photo
/Users/[[UNAME]]/mnt/NAS -fstype=smbfs ://[[USERNAME]]:[[PASSWORD]]@nas.loven/home

55
NAS_mounts/fix_mounts.sh Normal file
View File

@ -0,0 +1,55 @@
#!/bin/sh
#
# fix_mounts.sh - ensures autofs mounts are mounted by a user and not 'root'
#
# copyright 2016 scot.mcphee@gmail.com
#
# GPL 3.0 LICENCE https://www.gnu.org/licenses/gpl.txt
#
# This file should be run by 'root' as the 'sudo' should execute without stopping
# to ask for your password, unless you run this manually. See the
# org.autonomous.fixmounts.plist file which accompanies it. This plist executes
# the script every 15 seconds. I put mine in /Library/LaunchDaemons where it will
# be run as root whether there is a user logged in or not.
#
# autofsname - the name of the file in /etc/ that is specified in auto_master
# e.g.
# /- auto_nas -nosuid
# then it's 'auto_nas'
#
# mnt_usr - the userid of the user (you) that you want the mounts for
# mnt_pnt - the directory in the user dir where the mounts are
# t_mnt - using $mnt_usr and $mnt_pnt; the full path to the mounts
# mounts - space-separated list of mounts expected in $t_mnt
autofsname=auto_nas
mnt_usr=[[USERNAME]]
mnt_pnt=mnt
t_mnt=/Users/${mnt_usr}/${mnt_pnt}
mounts="music photo video NAS"
# don't change below here unless you know what you are doing with shell scripts.
all_mounts=`/sbin/mount | /usr/bin/grep $t_mnt | /usr/bin/grep -v "map $autofsname on $t_mnt"`
d=`/bin/date`
echo "fix_mounts [$d] checking $t_mnt for $mounts"
for mt in $mounts;
do
full_mount=${t_mnt}/${mt}
if [[ $all_mounts == *"$full_mount"* ]];
then
# it is mounted, let us see if it mounted by the user.
mm=`/bin/echo "$all_mounts" | /usr/bin/grep $full_mount`
if [[ ! $mm =~ on.$full_mount.*mounted.by.$mnt_usr ]]; then
echo "fix_mounts [$d] Remounting: $full_mount - because $mnt_usr not mounted $mm"
/usr/bin/sudo /sbin/umount $full_mount
# if resource is busy force unmount with diskutil DANGER
if [ ! $? ]; then /usr/sbin/diskutil unmount force $full_mount; fi
/usr/bin/sudo -u $mnt_usr cd $full_mount
fi
else
echo "fix_mounts [$d] Not mounted: $full_mount - ignoring"
fi
done

View File

@ -0,0 +1,34 @@
<?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>org.autonomous.fixmounts</string>
<key>ProgramArguments</key>
<array>
<string>/Users/[[USERNAME]]/bin/fix_mounts.sh</string>
</array>
<key>Nice</key>
<integer>10</integer>
<key>StartInterval</key>
<integer>15</integer>
<key>ThrottleInterval</key>
<integer>15</integer>
<key>RunAtLoad</key>
<false/>
<key>ProcessType</key>
<string>Background</string>
<key>StandardErrorPath</key>
<string>/var/log/fixmounts.log</string>
<key>StandardOutPath</key>
<string>/var/log/fixmounts.log</string>
</dict>
</plist>

49
NAS_mounts/setup.sh Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env bash
function create_directories()
{
mkdir ${HOME}/mnt
mkdir ${HOME}/mnt/music
mkdir ${HOME}/mnt/photos
mkdir ${HOME}/mnt/video
mkdir ${HOME}/mnt/NAS
}
function install_automount()
{
echo -n "Username for NAS: "
read NAS_USERNAME
echo -n "Password for NAS: "
read -s NAS_PASSWORD
echo
sed -e "s/\[\[USERNAME\]\]/${NAS_USERNAME}/" \
-e "s/\[\[PASSWORD\]\]/${NAS_PASSWORD}/" \
-e "s/\[\[UNAME\]\]/$(whoami)/" \
< "${DOTFILES}/NAS_mounts/auto_nas" \
| sudo tee "/etc/auto_nas_$(whoami)" >/dev/null
sudo chmod 600 "/etc/auto_nas_$(whoami)"
if ! grep "auto_nas_$(whoami)" < /etc/auto_master >/dev/null; then
echo "/- auto_nas_$(whoami) -nosuid" \
| sudo tee -a /etc/auto_master
fi
}
function install_fixer()
{
local plist=org.autonomous.fixmounts.plist
sed -e "s/\[\[USERNAME\]\]/$(whoami)/" \
< "${DOTFILES}/NAS_mounts/fix_mounts.sh" \
> ${HOME}/bin/fix_mounts.sh
chmod +x ${HOME}/bin/fix_mounts.sh
sed -e "s/\[\[USERNAME\]\]/$(whoami)/" \
< "${DOTFILES}/NAS_mounts/${plist}" \
| sudo tee /Library/LaunchDaemons/${plist} \
>/dev/null
sudo chmod 644 /Library/LaunchDaemons/${plist}
sudo launchctl load /Library/LaunchDaemons/${plist}
}
export DOTFILES=/Users/thomas/dotfiles
install_automount
install_fixer

20
fish/config.fish Executable file
View File

@ -0,0 +1,20 @@
if test "$SHLVL" -le 1
set -x DOTFILES {$HOME}/dotfiles
set -x PATH /usr/local/bin /usr/local/sbin $PATH
set -x PATH $DOTFILES/bin $PATH
if test -d $HOME/bin
set -x PATH $HOME/bin $PATH
end
set -x PATH . $PATH
set -x FISH_SETUP_PATH 'yes'
end
set -x LANG sv_SE.UTF-8
set -x LC_ALL sv_SE.UTF-8
set -x EDITOR nvim
alias v nvim
eval (python3 -m virtualfish)

6
fish/functions/bubu.fish Executable file
View File

@ -0,0 +1,6 @@
function bubu --description="Update, upgrade and clean up homebrew packages"
brew update
and brew outdated
and brew upgrade
and brew cleanup
end

View File

@ -0,0 +1,4 @@
function fish_greeting
end

29
fish/functions/fish_prompt.fish Executable file
View File

@ -0,0 +1,29 @@
function fish_prompt
set -l status_copy $status
if set -q VIRTUAL_ENV
echo -sn "(" (basename "$VIRTUAL_ENV") ")"
end
# Hostname with unique color
set_color (hostname -s | md5 | cut -c-6)
echo -sn (hostname -s)
# A yellow separator
# The color of this could be used to signify something
set_color yellow
echo -sn ':'
# Contracted path to PWD
set_color normal
echo -sn (prompt_pwd)
# A green or red >, depending on exit status of last command
if test "$status_copy" -ne 0
set_color red
else
set_color green
end
echo -sn ' > '
end

View File

@ -0,0 +1,34 @@
function fish_right_prompt
# Check if we are inside a version controlled directory (git only)
set -l ref (git symbolic-ref HEAD ^/dev/null)
if test -z $ref
return
end
# Check if any files have changes
git diff --no-ext-diff --quiet --exit-code ^/dev/null
or set -l dirty 'yes'
# Check if any files are staged
git diff-index --cached --quiet HEAD -- ^/dev/null
or set -l staged 'yes'
set_color normal
echo -sn '['
# Print branch name
# red if dirty
# yellow if staged
# green otherwise
if set -q staged
set_color yellow
else if set -q dirty
set_color red
else
set_color green
end
echo -sn (string replace refs/heads/ '' -- $ref)
set_color normal
echo -sn ']'
end

View File

@ -0,0 +1,4 @@
function fish_user_key_bindings
bind \t try_subst
end

10
fish/functions/g.fish Executable file
View File

@ -0,0 +1,10 @@
function g
# shortcut to git
# If no arguments are given, run git status and git l
if count $argv >/dev/null
git $argv
else
git status
git l -5
end
end

3
fish/functions/greb.fish Executable file
View File

@ -0,0 +1,3 @@
function greb --description "Git rebase entire history, interactively"
git rebase --interactive (git rev-list --max-parents=0 HEAD)
end

40
fish/functions/man.fish Executable file
View File

@ -0,0 +1,40 @@
function man --description "Format and display the on-line manual pages"
# Work around the "builtin" manpage that everything symlinks to,
# by prepending our fish datadir to man. This also ensures that man gives fish's
# man pages priority, without having to put fish's bin directories first in $PATH
# My changes (Thomas Lovén)
# Add color to the man pager
#
# blink
set -lx LESS_TERMCAP_mb (set_color -o red)
# bold
set -lx LESS_TERMCAP_md (set_color -o purple)
set -lx LESS_TERMCAP_me (set_color normal)
# standout
set -lx LESS_TERMCAP_so (set_color -b blue) (set_color yellow)
set -lx LESS_TERMCAP_se (set_color normal)
# underline
set -lx LESS_TERMCAP_us (set_color -u green)
set -lx LESS_TERMCAP_ue (set_color normal)
set -l manpath
if set -q MANPATH
set manpath $MANPATH
else if command -qs manpath
set manpath (command manpath)
end
# Notice local exported copy of the variable.
set -lx MANPATH $manpath
set -l fish_manpath (dirname $__fish_datadir)/fish/man
if test -d "$fish_manpath" -a -n "$MANPATH"
set MANPATH $fish_manpath:$MANPATH
# Invoke man with this manpath, and we're done.
command man $argv
return
end
# If fish's man pages could not be found, just invoke man normally
command man $argv
end

4
fish/functions/mcd.fish Executable file
View File

@ -0,0 +1,4 @@
function mcd --description "Make directory and enter it"
mkdir -p $argv
and cd $argv
end

14
fish/functions/try_subst.fish Executable file
View File

@ -0,0 +1,14 @@
function try_subst
# Use s/word/replacement<tab> to replace word with replacement
# in last command
commandline | read -l saved_commandline
set -l pattern '^s/..*/.*$'
if commandline -t | grep -E -q "$pattern"
commandline -tr (echo -n "$history[1]" | sed -e (commandline -t)/g)
else
commandline -f complete
end
end

21
fish/setup.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
function setup_fish()
{
brew install fish
if ! grep /usr/local/bin/fish < /etc/shells >/dev/null; then
echo /usr/local/bin/fish | sudo tee -a /etc/shells
chsh -s /usr/local/bin/fish
fi
}
function link_config()
{
mkdir ${HOME}/.config
ln -s ${DOTFILES}/fish ${HOME}/.config/.
}
export DOTFILES=/Users/thomas/dotfiles
setup_fish
link_config

View File

@ -26,32 +26,42 @@ function cask()
function install_casks()
{
cask google-chrome
cask iterm2
cask docker
cask caskroom/drivers/logitech-options
cask crisidev/chunkwm/chunkwm
cask koekeishiya/formulae/khd
}
function install_brews()
{
#/usr/local/bin/brew update
brew fish
brew tmux
brew git
brew arp-scan
brew neovim
}
function setup_fish()
function setup_kitty()
{
brew fish
echo /usr/local/bin/fish | sudo tee -a /etc/shells
chsh -s /usr/local/bin/fish
# Copy kitty.app to /Applications
#cp ${KITTY_PATH} /Applications/.
ln -s ${DOTFILES}/kitty.conf ${HOME}/Library/Preferences/kitty/kitty.conf
}
install_brews
install_casks
function setup_ssh()
{
# copy private key to .ssh
# cp ${KEYFILE} ~/.ssh/thomas_rsa
# chmod 400 ~/.ssh/thomas_rsa
# ssh-add -K ~/.ssh/thomas_rsa
ln -s ${DOTFILES}/ssh_config ${HOME}/.ssh/config
}
export DOTFILES=/Users/thomas/dotfiles
#install_brews
#install_casks
#setup_fish
#setup_ssh
#setup_wm
#setup_kitty
setup_home

30
kitty.conf Normal file
View File

@ -0,0 +1,30 @@
font_size 8.0
# macos_hide_titlebar yes
# term xterm-256color
background #282828
foreground #ebdbb2
color0 #282828
color8 #928374
color1 #cc241d
color9 #fb4934
color2 #98971a
color10 #b8bb26
color3 #d79921
color11 #fabd2f
color4 #458588
color12 #83a598
color5 #b16286
color13 #d3869b
color6 #689d6a
color14 #8ec07c
color7 #a89984
color15 #ebdbb2
map super+v paste_from_clipboard
map super+c copy_to_clipboard
map super+minus increase_font_size
map super+shift+minus decrease_font_size
map super+0 restore_font_size

4
ssh_config Normal file
View File

@ -0,0 +1,4 @@
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/thomas_rsa

107
wm/chunkwmrc Executable file
View File

@ -0,0 +1,107 @@
#!/bin/bash
#
# NOTE: specify the absolutepath to the directory to use when
# loading a plugin. '~' expansion is supported.
#
chunkc core::plugin_dir /usr/local/opt/chunkwm/share/chunkwm/plugins
#
# NOTE: if enabled, chunkwm will monitor the specified plugin_dir
# and automatically reload any '.so' file that is changed.
#
chunkc core::hotload 1
#
# NOTE: the following are config variables for the chunkwm-tiling plugin.
#
# desktop1 Höger skärm
# desktop2 Vänster skärm
chunkc set global_desktop_mode bsp
chunkc set 5_desktop_mode float
chunkc set 1_desktop_tree ~/.chunkwm_layouts/dev_1
chunkc set global_desktop_offset_top 20
chunkc set global_desktop_offset_bottom 20
chunkc set global_desktop_offset_left 20
chunkc set global_desktop_offset_right 20
chunkc set global_desktop_offset_gap 15
chunkc set 1_desktop_offset_top 30
chunkc set 1_desktop_offset_bottom 30
chunkc set 1_desktop_offset_left 30
chunkc set 1_desktop_offset_right 30
chunkc set 1_desktop_offset_gap 30
chunkc set 2_desktop_offset_top 20
chunkc set 2_desktop_offset_bottom 20
chunkc set 2_desktop_offset_left 20
chunkc set 2_desktop_offset_right 20
chunkc set 2_desktop_offset_gap 20
chunkc set desktop_padding_step_size 10.0
chunkc set desktop_gap_step_size 5.0
chunkc set bsp_spawn_left 1
chunkc set bsp_optimal_ratio 1.618
chunkc set bsp_split_mode optimal
chunkc set bsp_split_ratio 0.5
chunkc set window_focus_cycle monitor
chunkc set mouse_follows_focus 1
chunkc set window_float_next 0
chunkc set window_float_center 1
chunkc set window_region_locked 1
#
# NOTE: shell commands require escaped quotes
# to pass value containing a whitespace.
#
# chunkc set mouse_modifier \"cmd shift\"
chunkc set mouse_modifier fn
chunkc set preselect_border_color 0xffffff00
chunkc set preselect_border_width 4
chunkc set preselect_border_radius 0
#
# NOTE: these settings require chwm-sa.
# (https://github.com/koekeishiya/chwm-sa)
#
chunkc set window_float_topmost 0
chunkc set window_fade_inactive 0
chunkc set window_fade_alpha 0.85
chunkc set window_fade_duration 0.5
#
# NOTE: the following are config variables for the chunkwm-border plugin.
#
#chunkc set focused_border_color 0xffc0b18b
chunkc set focused_border_color 0xff689d6a
chunkc set focused_border_width 4
chunkc set focused_border_radius 0
chunkc set focused_border_skip_floating 0
#
# NOTE: specify plugins to load when chunkwm starts.
# if chunkc plugin_dir is not set, the absolutepath is necessary.
#
chunkc core::load tiling.so
# chunkc core::load ffm.so
chunkc core::load border.so
#
# NOTE: shell commands require escaped quotes
# to pass value containing a whitespace.
#
chunkc tiling::rule --owner \"System Preferences\" --subrole AXStandardWindow --state tile
chunkc tiling::rule --owner Finder --name Copy --state float

109
wm/khdrc Normal file
View File

@ -0,0 +1,109 @@
# reload config
cmd + alt + ctrl - r : khd -e "reload"
# open terminal, blazingly fast compared to iTerm/Hyper
cmd - return : open -na /Applications/kitty.app
# Default border: Aqua
khd mode default on_enter chunkc border::color 0xff689d6a
# focus window
alt - h : chunkc tiling::window --focus west
alt - j : chunkc tiling::window --focus south
alt - k : chunkc tiling::window --focus north
alt - l : chunkc tiling::window --focus east
alt + shift - 1 : chunkc tiling::monitor -f 1
alt + shift - 2 : chunkc tiling::monitor -f 2
# Move mode: orange
alt - w: khd -e "mode activate move"
move + alt - w: khd -e "mode activate default"
move - escape: khd -e "mode activate default"
move - space: khd -e "mode activate default"
khd mode move on_enter chunkc border::color 0xffd65d0e
# swap window
move - h : chunkc tiling::window --swap west; khd -e "mode activate default"
move - j : chunkc tiling::window --swap south; khd -e "mode activate default"
move - k : chunkc tiling::window --swap north; khd -e "mode activate default"
move - l : chunkc tiling::window --swap east; khd -e "mode activate default"
# move window
move + shift - h : chunkc tiling::window --warp west; khd -e "mode activate default"
move + shift - j : chunkc tiling::window --warp south; khd -e "mode activate default"
move + shift - k : chunkc tiling::window --warp north; khd -e "mode activate default"
move + shift - l : chunkc tiling::window --warp east; khd -e "mode activate default"
# move window to monitor
move - 1 : chunkc tiling::window --send-to-monitor 1; chunkc tiling::monitor -f 1; khd -e "mode activate default"
move - 2 : chunkc tiling::window --send-to-monitor 2; chunkc tiling::monitor -f 2; khd -e "mode activate default"
# move floating windows / windows on a floating space
move - up : chunkc tiling::window --warp-floating fullscreen; khd -e "mode activate default"
move - left : chunkc tiling::window --warp-floating left; khd -e "mode activate default"
move - right : chunkc tiling::window --warp-floating right; khd -e "mode activate default"
move + cmd - left : chunkc tiling::window --warp-floating top-left; khd -e "mode activate default"
move + cmd - right : chunkc tiling::window --warp-floating top-right; khd -e "mode activate default"
move + shift + cmd - left : chunkc tiling::window --warp-floating bottom-left; khd -e "mode activate default"
move + shift + cmd - right : chunkc tiling::window --warp-floating bottom-right; khd -e "mode activate default"
#
# toggle window fullscreen
move - f : chunkc tiling::window --toggle fullscreen; khd -e "mode activate default"
# toggle window native fullscreen
move + shift - f : chunkc tiling::window --toggle native-fullscreen
# toggle window parent zoom
move - d : chunkc tiling::window --toggle parent; khd -e "mode activate default"
# toggle window split type
move - e : chunkc tiling::window --toggle split; khd -e "mode activate default"
# float / unfloat window
move - t : chunkc tiling::window --toggle float; khd -e "mode activate default"
# toggle sticky, float and resize to picture-in-picture size
move - s : chunkc tiling::window --toggle sticky;\
chunkc tiling::window --warp-floating pip-right; khd -e "mode activate default"
#
# rotate tree
move - r : chunkc tiling::desktop --rotate 90
# mirror tree y-axis
move - y : chunkc tiling::desktop --mirror vertical
# mirror tree x-axis
move - x : chunkc tiling::desktop --mirror horizontal
# toggle desktop offset
move - a : chunkc tiling::desktop --toggle offset; khd -e "mode activate default"
#
# change layout of desktop
move + shift - a : chunkc tiling::desktop --layout bsp; khd -e "mode activate default"
move + shift - s : chunkc tiling::desktop --layout monocle; khd -e "mode activate default"
move + shift - d : chunkc tiling::desktop --layout float; khd -e "mode activate default"
# Resize mode: yellow
alt - e: khd -e "mode activate resize"
resize + alt - e: khd -e "mode activate default"
resize - space: khd -e "mode activate default"
resize - escape: khd -e "mode activate default"
khd mode resize on_enter chunkc border::color 0xffd79921
# equalize size of windows
resize - 0 : chunkc tiling::desktop --equalize
# increase region size
resize - a : chunkc tiling::window --use-temporary-ratio 0.1 --adjust-window-edge west
resize - s : chunkc tiling::window --use-temporary-ratio 0.1 --adjust-window-edge south
resize - w : chunkc tiling::window --use-temporary-ratio 0.1 --adjust-window-edge north
resize - d : chunkc tiling::window --use-temporary-ratio 0.1 --adjust-window-edge east
# decrease region size
resize + shift - a : chunkc tiling::window --use-temporary-ratio -0.1 --adjust-window-edge west
resize + shift - s : chunkc tiling::window --use-temporary-ratio -0.1 --adjust-window-edge south
resize + shift - w : chunkc tiling::window --use-temporary-ratio -0.1 --adjust-window-edge north
resize + shift - d : chunkc tiling::window --use-temporary-ratio -0.1 --adjust-window-edge east
# float next window to be tiled
# shift + alt - t : chunkc set window_float_next 1
# ctrl + alt - w : chunkc tiling::desktop --deserialize ~/.chunkwm_layouts/dev_1
# remap caps-lock to escape for this config only !!!
# macos sierra can also perform this remap for a given keyboard
# - capslock : khd -p "- escape"
# key remap for norwegian layout \ { }
# cmd - 7 : khd -p "shift + alt - 7"
# cmd - 8 : khd -p "shift + alt - 8"
# cmd - 9 : khd -p "shift + alt - 9"

16
wm/setup.sh Normal file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
function setup_wm()
{
brew crisidev/homebrew-chunkwm/chunkwm
brew koekeishiya/formulae/khd
ln -s ${DOTFILES}/wm/khdrc ${HOME}/.khdrc
ln -s ${DOTFILES}/wm/chunkwmrc ${HOME}/.chunkwmrc
if ! /usr/local/bin/brew services list | grep chunkwm >/dev/null; then
/usr/local/bin/brew services start khd
/usr/local/bin/brew services start chunkwm
fi
}
export DOTFILES=/Users/thomas/dotfiles
setup_wm