summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.Xresources2
-rw-r--r--.bashrc7
-rw-r--r--.config/i3/config4
-rw-r--r--.vim/plugin/cscope_maps.vim167
-rwxr-xr-xbin/hdmi8
-rwxr-xr-xbin/vm258
6 files changed, 439 insertions, 7 deletions
diff --git a/.Xresources b/.Xresources
index 7ca66a3..64ab14c 100644
--- a/.Xresources
+++ b/.Xresources
@@ -30,6 +30,8 @@ xterm*decTerminalID: vt340
xterm*allowWindowOps : False
xterm*disallowedWindowOps : 1,2,3,4,5,6,7,8,9,11,13,18,19,20,21,GetSelection,SetSelection,SetWinLines,SetXprop
+! Colors optimized for a light background
+!
! Black + DarkGrey
*color0: #000000
*color8: #555753
diff --git a/.bashrc b/.bashrc
index f20fbdd..642c6d7 100644
--- a/.bashrc
+++ b/.bashrc
@@ -46,6 +46,7 @@ alias cl='cf xft:Mono:size=12'
alias cp='cp --reflink'
alias ls='ls --color=auto -v'
alias ll='ls -AlFhv'
+alias more='less'
alias vi='vim'
alias view='vim -R'
#alias op='xdg-open'
@@ -131,7 +132,9 @@ unset base
# Display git status in prompt
. ~/.bash-powerline.sh
-# export PS1='; '
+# export PS1='; '
# load Nix config files (aka auto-completion etc.)
-export XDG_DATA_DIRS="$HOME/.nix-profile/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
+#export XDG_DATA_DIRS="$HOME/.nix-profile/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
+
+eval "$(direnv hook bash)"
diff --git a/.config/i3/config b/.config/i3/config
index 84f31c2..182f119 100644
--- a/.config/i3/config
+++ b/.config/i3/config
@@ -68,6 +68,7 @@ for_window [class="Display"] floating enable
for_window [class="Feedreader"] floating enable
for_window [class="feh"] floating enable
for_window [class="firefox"] floating enable
+for_window [class="fluent-reader"] floating enable
for_window [class="Geeqie"] floating enable
for_window [class="Gpicview"] floating enable
for_window [class="Ghb"] floating enable
@@ -79,8 +80,9 @@ for_window [class="libreoffice"] floating enable
for_window [class="Liferea"] floating enable
for_window [class="llpp"] floating enable
for_window [class="MuPDF"] floating enable
-for_window [class="Pavucontrol"] floating enable
for_window [class="Org.gnome.Software"] floating enable
+for_window [class="Pavucontrol"] floating enable
+for_window [title="QEMU"] floating enable
for_window [class="Signal"] floating enable
for_window [class="Slack"] floating enable
for_window [class="Spotify"] floating enable
diff --git a/.vim/plugin/cscope_maps.vim b/.vim/plugin/cscope_maps.vim
new file mode 100644
index 0000000..abcae71
--- /dev/null
+++ b/.vim/plugin/cscope_maps.vim
@@ -0,0 +1,167 @@
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" CSCOPE settings for vim
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+"
+" This file contains some boilerplate settings for vim's cscope interface,
+" plus some keyboard mappings that I've found useful.
+"
+" USAGE:
+" -- vim 6: Stick this file in your ~/.vim/plugin directory (or in a
+" 'plugin' directory in some other directory that is in your
+" 'runtimepath'.
+"
+" -- vim 5: Stick this file somewhere and 'source cscope.vim' it from
+" your ~/.vimrc file (or cut and paste it into your .vimrc).
+"
+" NOTE:
+" These key maps use multiple keystrokes (2 or 3 keys). If you find that vim
+" keeps timing you out before you can complete them, try changing your timeout
+" settings, as explained below.
+"
+" Happy cscoping,
+"
+" Jason Duell jduell@alumni.princeton.edu 2002/3/7
+""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+
+" This tests to see if vim was configured with the '--enable-cscope' option
+" when it was compiled. If it wasn't, time to recompile vim...
+if has("cscope")
+
+ """"""""""""" Standard cscope/vim boilerplate
+
+ " use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
+ set cscopetag
+
+ " check cscope for definition of a symbol before checking ctags: set to 1
+ " if you want the reverse search order.
+ set csto=0
+
+ " add any cscope database in current directory
+ if filereadable("cscope.out")
+ cs add cscope.out
+ " else add the database pointed to by environment variable
+ elseif $CSCOPE_DB != ""
+ cs add $CSCOPE_DB
+ endif
+
+ " show msg when any other cscope db added
+ set cscopeverbose
+
+
+ """"""""""""" My cscope/vim key mappings
+ "
+ " The following maps all invoke one of the following cscope search types:
+ "
+ " 's' symbol: find all references to the token under cursor
+ " 'g' global: find global definition(s) of the token under cursor
+ " 'c' calls: find all calls to the function name under cursor
+ " 't' text: find all instances of the text under cursor
+ " 'e' egrep: egrep search for the word under cursor
+ " 'f' file: open the filename under cursor
+ " 'i' includes: find files that include the filename under cursor
+ " 'd' called: find functions that function under cursor calls
+ "
+ " Below are three sets of the maps: one set that just jumps to your
+ " search result, one that splits the existing vim window horizontally and
+ " diplays your search result in the new window, and one that does the same
+ " thing, but does a vertical split instead (vim 6 only).
+ "
+ " I've used CTRL-\ and CTRL-@ as the starting keys for these maps, as it's
+ " unlikely that you need their default mappings (CTRL-\'s default use is
+ " as part of CTRL-\ CTRL-N typemap, which basically just does the same
+ " thing as hitting 'escape': CTRL-@ doesn't seem to have any default use).
+ " If you don't like using 'CTRL-@' or CTRL-\, , you can change some or all
+ " of these maps to use other keys. One likely candidate is 'CTRL-_'
+ " (which also maps to CTRL-/, which is easier to type). By default it is
+ " used to switch between Hebrew and English keyboard mode.
+ "
+ " All of the maps involving the <cfile> macro use '^<cfile>$': this is so
+ " that searches over '#include <time.h>" return only references to
+ " 'time.h', and not 'sys/time.h', etc. (by default cscope will return all
+ " files that contain 'time.h' as part of their name).
+
+
+ " To do the first type of search, hit 'CTRL-\', followed by one of the
+ " cscope search types above (s,g,c,t,e,f,i,d). The result of your cscope
+ " search will be displayed in the current window. You can use CTRL-T to
+ " go back to where you were before the search.
+ "
+
+ " MV: replace C-\ by C-,
+ nmap <C-,>s :cs find s <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-,>g :cs find g <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-,>c :cs find c <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-,>t :cs find t <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-,>e :cs find e <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-,>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
+ nmap <C-,>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
+ nmap <C-,>d :cs find d <C-R>=expand("<cword>")<CR><CR>
+
+
+ " Using 'CTRL-spacebar' (intepreted as CTRL-@ by vim) then a search type
+ " makes the vim window split horizontally, with search result displayed in
+ " the new window.
+ "
+ " (Note: earlier versions of vim may not have the :scs command, but it
+ " can be simulated roughly via:
+ " nmap <C-@>s <C-W><C-S> :cs find s <C-R>=expand("<cword>")<CR><CR>
+
+ " MV: replace C-@ by C-;
+ nmap <C-;>s :scs find s <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-;>g :scs find g <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-;>c :scs find c <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-;>t :scs find t <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-;>e :scs find e <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-;>f :scs find f <C-R>=expand("<cfile>")<CR><CR>
+ nmap <C-;>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
+ nmap <C-;>d :scs find d <C-R>=expand("<cword>")<CR><CR>
+
+
+ " Hitting CTRL-space *twice* before the search type does a vertical
+ " split instead of a horizontal one (vim 6 and up only)
+ "
+ " (Note: you may wish to put a 'set splitright' in your .vimrc
+ " if you prefer the new window on the right instead of the left
+
+ nmap <C-@><C-@>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-@><C-@>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-@><C-@>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-@><C-@>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-@><C-@>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>
+ nmap <C-@><C-@>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR>
+ nmap <C-@><C-@>i :vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
+ nmap <C-@><C-@>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>
+
+
+ """"""""""""" key map timeouts
+ "
+ " By default Vim will only wait 1 second for each keystroke in a mapping.
+ " You may find that too short with the above typemaps. If so, you should
+ " either turn off mapping timeouts via 'notimeout'.
+ "
+ "set notimeout
+ "
+ " Or, you can keep timeouts, by uncommenting the timeoutlen line below,
+ " with your own personal favorite value (in milliseconds):
+ "
+ "set timeoutlen=4000
+ "
+ " Either way, since mapping timeout settings by default also set the
+ " timeouts for multicharacter 'keys codes' (like <F1>), you should also
+ " set ttimeout and ttimeoutlen: otherwise, you will experience strange
+ " delays as vim waits for a keystroke after you hit ESC (it will be
+ " waiting to see if the ESC is actually part of a key code like <F1>).
+ "
+ "set ttimeout
+ "
+ " personally, I find a tenth of a second to work well for key code
+ " timeouts. If you experience problems and have a slow terminal or network
+ " connection, set it higher. If you don't set ttimeoutlen, the value for
+ " timeoutlent (default: 1000 = 1 second, which is sluggish) is used.
+ "
+ "set ttimeoutlen=100
+
+endif
+
+
diff --git a/bin/hdmi b/bin/hdmi
index d6f206a..e6e3094 100755
--- a/bin/hdmi
+++ b/bin/hdmi
@@ -2,8 +2,8 @@
# Toggle auxiliary HDMI screen on/off when connected/disconnected.
opt="--auto --left-of eDP1"
-#opt="--auto --right-of eDP-1"
-#opt="--auto --above eDP-1"
+#opt="--auto --right-of eDP1"
+#opt="--auto --above eDP1"
# Also add the following rule to /etc/udev/rules.d/hdmi.rules
# KERNEL=="card0", SUBSYSTEM=="drm", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/marc/.Xauthority", RUN+="/home/marc/bin/hdmi"
@@ -11,5 +11,5 @@ opt="--auto --left-of eDP1"
# wait for the screen to settle
sleep 3
-xrandr | grep -q 'HDMI1 connected' || opt="--off"
-xrandr --output HDMI1 $opt
+xrandr | grep -q '^DP1 connected' || opt="--off"
+xrandr --output DP1 $opt
diff --git a/bin/vm b/bin/vm
new file mode 100755
index 0000000..8b4da42
--- /dev/null
+++ b/bin/vm
@@ -0,0 +1,258 @@
+#!/bin/sh
+
+# Manage virtual machines
+#
+# Prereq:
+# - curl
+# - cdrtools (isoinfo)
+# - expect
+# - qemu
+# - screen
+#
+# TODO:
+# - extract bzImage and initrd.gz with isoinfo
+# - ssh scripts to finish install (once ssh is ready)
+#
+# DONE:
+# - setup vde and networking
+# - setup ssh keys so it is possible to ssh in vm from host
+#
+unset CDPATH
+export LC_ALL=C IFS='
+'
+
+version='vm-0.1'
+
+arch=$(uname -m)
+sys=$(uname -s)
+alpine_version='3.15.0'
+pubkey=$HOME/.ssh/id_rsa.pub
+dir="${VM_DIR:-$HOME/.vm}"
+
+console() {
+ usage 'console name' 'Attach a console to a virtual machine' && return
+ [ "$1" ] || die "missing argument"
+ is_running "$1" && screen -r "vm!$1!"
+}
+
+create() {
+ usage 'create [-s size] name' 'Create an alpinelinux disk image' && return
+ size=8g
+ while getopts :s: opt; do
+ case $opt in
+ s) size=$OPTARG ;;
+ *) Opth=2 create_alpine_image; return ;;
+ esac
+ done
+ shift $((OPTIND - 1))
+ [ -d "$dir/$1" ] && die "create failed: $dir/$1 already exists"
+ mkdir "$dir/$1"
+ cd "$dir/$1" || die "create failed: invalid directory $dir/$1"
+ qemu-img create "$1.raw" "$size" || die "create failed"
+ mac=$(new_macaddr)
+ ip=$(new_ip)
+ hdd="$1.raw"
+ echo "hdd=$hdd
+mac=$mac
+ip=$ip" >> config
+
+ # Before install do not use virtio, as devices may not recognized as bootable
+ # TODO: alternate way: extract kernel and initrd files and pass them directly to qemu
+ screen -S "vm!$1!" -d -m qemu-system-$arch -nographic \
+ -cdrom ../alpine-iso/alpine-virt-$alpine_version-$arch.iso \
+ -hdd "$hdd" -net nic,macaddr=$mac -net vde
+ setup_alpine "$1"
+ post_setup_alpine "$1"
+}
+
+die() { [ "$1" ] && echo "$0: $*" >&2; exit 1; }
+
+help() {
+ usage 'help' 'Print this help text' && return
+ printf "$version\n Manage virtual machines\n\nUsage: vm command [options] [args]\n"
+ Opth=1; for c in $Cmdlist; do $c; done
+}
+
+init() {
+ mkdir -p "$dir"
+}
+
+init_alpine_iso() {
+ usage init_alpine_iso '' && return
+ mkdir -p "$dir/alpine-iso"
+ iso_url="https://dl-cdn.alpinelinux.org/alpine/v${alpine_version%.*}/releases/$arch"
+ iso="alpine-virt-$alpine_version-$arch.iso"
+ cd "$dir/alpine-iso"
+ [ -f "$iso" ] || curl -LO "$iso_url/$iso" || rm -f "$iso"
+ echo "iso=$iso
+" > config
+ echo 10 > ../index
+}
+
+is_running() { screen -ls "vm!$1!" >/dev/null 2>&1; }
+
+ls() {
+ usage 'ls' 'list virtual machines' && return
+ init && cd "$dir" || die "could not change dir to $dir"
+ for i in */; do
+ i=${i%/}
+ [ "$i" = '*' ] && continue
+ is_running "$i" && state=active || state=stopped
+ printf "%-20s %s\n" "$i" "$state"
+ done
+}
+
+new_ip() {
+ read index < $dir/index
+ index=$((index + 1))
+ echo "$index" > $dir/index
+ echo "10.0.2.$index/24"
+}
+
+new_macaddr() { printf 'de:ad:be:ef:%02x:%02x\n' $((RANDOM % 256)) $((RANDOM % 256)); }
+
+pidof() {
+ usage 'pidof name' 'print the PID of a virtual machine' && return
+ p=$(screen -ls "vm!$1!" | awk 'NR==2 {print substr($1, 1, index($1, ".")-1)}')
+ [ "$p" ] && pgrep -P $p
+}
+
+post_setup_alpine() {
+ start "$1"
+ read proto key id < "$pubkey"
+ # echo '
+ expect -c '
+ set timeout -1
+ spawn screen -x "vm!'$1'!"
+ expect {
+ " login: " { send "root\r"; exp_continue }
+ "Password: " { send "root\r"; exp_continue }
+ ":~# "
+ }
+ send "mkdir -pm 0700 .ssh\r"
+ expect ":~# "
+ send "echo '$proto' '$key' '$id' >.ssh/authorized_keys\r"
+ expect ":~# "
+ send "exit\r"
+ '
+}
+
+# setup_alpine automates alpine installation from iso to image.
+# When done, base image system is ready, with storage and network up.
+# No user nor ssh access configured yet.
+# TODO: custom network (in case of no dhcp).
+setup_alpine() {
+ usage 'setup_alpine' && return
+ expect -c '
+ set timeout -1
+ spawn screen -x "vm!'$1'!"
+ expect {
+ "localhost login: " { send "root\r"; exp_continue }
+ "localhost:~# " { send "SWAP_SIZE=0 setup-alpine\r"; exp_continue }
+ "Select keyboard layout: " { send "\r"; exp_continue }
+ "Enter system hostname" { send "'$1'\r"; exp_continue }
+ "Which one do you want to initialize?" { send "\r"; exp_continue }
+ "Ip address for eth0?" { send "'$ip'\r"; exp_continue }
+ "Gateway?" { send "10.0.2.2\r"; exp_continue }
+ "manual network configuration?" { send "\r"; exp_continue }
+ "DNS domain name?" { send "lan\r"; exp_continue }
+ "DNS nameserver(s)?" { send "10.0.2.2 1.1.1.1\r"; exp_continue }
+ "New password:" { send "root\r"; exp_continue }
+ "Retype password:" { send "root\r"; exp_continue }
+ "Which timezone are you in?" { send "\r"; exp_continue }
+ "HTTP/FTP proxy URL?" { send "\r"; exp_continue }
+ "Enter mirror number " { send "\r"; exp_continue }
+ "Which SSH server?" { send "\r"; exp_continue }
+ "Which disk(s) would you like to use?" { send "sda\r"; exp_continue }
+ "How would you like to use it?" { send "sys\r"; exp_continue }
+ "Erase the above disk(s) and continue?" { send "y\r"; exp_continue }
+ "Installation is complete" { send "poweroff\r" }
+ }
+ interact
+ '
+}
+
+start_vde() {
+ usage start_vde && return
+ sudo sh <<- EOT
+ vde_switch -tap tap0 -sock /tmp/vde.ctl -daemon -mod 666
+ sleep 1
+ ip address add 10.0.2.2/24 dev tap0
+ ip link set tap0 up
+ echo 1 > /proc/sys/net/ipv4/ip_forward
+ iptables -t nat -A POSTROUTING -s 10.0.2.0/24 -o eth0 -j MASQUERADE
+ iptables -t nat -A POSTROUTING -s 10.0.2.0/24 -o wlan0 -j MASQUERADE
+ EOT
+ #slirpvde --dhcp --daemon
+}
+
+stop_vde() {
+ # killall slirpvde
+ sudo sh <<- EOT
+ iptables -t nat -D POSTROUTING -s 10.0.2.0/24 -o eth0 -j MASQUERADE
+ iptables -t nat -D POSTROUTING -s 10.0.2.0/24 -o wlan0 -j MASQUERADE
+ ip link set tap0 down
+ killall vde_switch
+ EOT
+}
+
+start() {
+ usage 'start [-acd] name' 'start a virtual machine' && return
+ while getopts :acd opt; do
+ case $opt in
+ a) opta=1 ;;
+ c) boot=c ;;
+ d) boot=d ;;
+ esac
+ done
+ shift $((OPTIND -1))
+ [ "$1" ] || die 'start failed: name missing'
+ cd "$dir/$1" || die "start failed: invalid directory $dir/$1"
+ is_running "$1" || start_qemu "$1"
+ [ "$opta" ] && console "$1"
+}
+
+start_qemu() (
+ opt='-nographic -cpu max'
+ [ "$sys" = Linux ] && opt="$opt -enable-kvm"
+ . ./config || die "could not source $PWD/config"
+ exec 1>>qemu.log 2>&1
+ date +%F_%T
+ set -x
+ screen -S "vm!$1!" -d -m qemu-system-$arch $opt \
+ ${smp+-smp $smp} \
+ ${ram+-m $ram} \
+ ${mac+-net nic,macaddr=$mac,model=virtio-net-pci} -net vde \
+ ${hdd+-drive file="$hdd",if=virtio,media=disk,format=raw} \
+ ${iso+-drive file="$iso",if=virtio,media=cdrom,format=raw} \
+ ${boot+-boot $boot}
+)
+
+stop() {
+ usage 'stop name' 'stop a virtual machine' && return
+ is_running "$1" && kill "$(pidof "$1")"
+}
+
+usage() {
+ case $Opth in
+ 1) printf " %-34s %s\n" "$1" "$2" ;;
+ 2) printf "$0 $1\n\t$2\n" ;;
+ *) return 1 ;;
+ esac
+}
+
+version() {
+ usage 'version' 'Print version' && return
+ echo "$version"
+}
+
+Cmdlist='console create help init_alpine_iso ls pidof setup_alpine start start_vde stop version'
+[ "$1" ] && C=$1 && shift 1 || { help; exit 1; }
+#for c in $Cmdlist; do
+# case $c in
+# ("$C") cmd=$c; break ;;
+# ("$C"*) [ "$cmd" ] && die "ambiguous command $C" || cmd=$c ;;
+# esac
+#done
+cmd=$C
+[ "$cmd" ] || { help; exit 1; } && $cmd "$@"