~rycwo/workspace

ea0e9c7902663251b46e444331e7cdbac8919b4c — Ryan Chan 2 years ago 997b985
Various dotfile updates and new scripts

Changes include:
- Remove Ruby variables from .bash_profile
- Simplify exclusion paths from backup-host script
- Add screen capture script
- Add barrierc helper script
- Remove xdg config files
6 files changed, 81 insertions(+), 29 deletions(-)

M bash/.bash_profile
M bin/backup-host
A bin/connect-barrier
A bin/screencap
D xdg/user-dirs.dirs
D xdg/user-dirs.locale
M bash/.bash_profile => bash/.bash_profile +0 -1
@@ 10,5 10,4 @@ export npm_config_prefix="$HOME""/.node_modules"
PATH="$PATH"":""$GOPATH""/bin"                         # Go executables
PATH="$PATH"":""$HOME""/.local/bin"                    # Python scripts
PATH="$PATH"":""$HOME""/.node_modules/bin"             # Node scripts
PATH="$PATH"":""$(ruby -e "puts Gem.user_dir")""/bin"  # Ruby gems
PATH="$PATH"":""$HOME""/dev/workspace/bin"             # Personal executables

M bin/backup-host => bin/backup-host +1 -12
@@ 26,21 26,10 @@ readonly paths=(
)
readonly exclude_paths=(
    "/home/rycwo/.borg-passphrase"
    "/home/rycwo/.bundle"
    "/home/rycwo/.cache"
    "/home/rycwo/.cmake"
    "/home/rycwo/.gem"
    "/home/rycwo/.mozilla"
    "/home/rycwo/.node_modules"
    "/home/rycwo/.npm"
    "/home/rycwo/.renderdoc"
    "/home/rycwo/.rustup"
    "/home/rycwo/.secret"
    "/home/rycwo/.vagrant.d"
    "/home/rycwo/.virtualbox"
    "/home/rycwo/go"
    "/home/rycwo/dev/package"
    "/home/rycwo/dev/repo/third-party")
	"/home/rycwo/go")
exclude_file="$(mktemp)"

exit_() {

A bin/connect-barrier => bin/connect-barrier +3 -0
@@ 0,0 1,3 @@
#!/usr/bin/env sh
barrierc --no-tray "$@" &
setxkbmap -device "$(xinput list --id-only "Virtual core XTEST keyboard")" "gb"

A bin/screencap => bin/screencap +77 -0
@@ 0,0 1,77 @@
#!/usr/bin/env python
from collections import OrderedDict
from contextlib import contextmanager
from datetime import datetime
from pathlib import Path
from tempfile import NamedTemporaryFile
import argparse
import os
import subprocess
import sys


@contextmanager
def mktemp(**kwargs):
    tmpfile = NamedTemporaryFile(delete=False, **kwargs)
    # Immediately close the returned file object so we can write to it elsewhere
    tmpfile.close()
    try:
        yield tmpfile.name
    finally:
        # It is the caller's responsibility to close the file after using it
        os.unlink(tmpfile.name)


def output_filename():
    # Generate output filename
    timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
    return Path(f"screencap_{timestamp}.mkv")


def generate_args(flags):
    for k, v in flags.items():
        yield k
        yield v


def main():
    parser = argparse.ArgumentParser("Record screen contents")
    parser.add_argument("-o", "--output", type=Path, default=output_filename())
    parser.add_argument("--resolution", type=str, default="1920x1080")
    parser.add_argument("--framerate", type=float, default=60.0)
    parser.add_argument("--monitor", type=str, default=":0.0")
    parser.add_argument("--quality", type=int, default=18)
    parser.add_argument("--pixel-format", type=str, default="yuv420p")
    args = parser.parse_args()

    with mktemp(suffix=".mkv") as tmpfilename:
        flags = OrderedDict([])
        flags["-video_size"] = args.resolution
        flags["-framerate"] = str(args.framerate)
        flags["-f"] = "x11grab"
        flags["-i"] = args.monitor
        flags["-c:v"] = "libx264rgb"
        flags["-crf"] = "0"  # Lossless quality
        flags["-preset"] = "ultrafast"  # Low CPU usage

        process_args = list(generate_args(flags))
        process_args.append(tmpfilename)
        # FIXME: This presents a security threat as the file can be created
        # between removal and ffmpeg invocation.
        os.unlink(tmpfilename)
        subprocess.run(["ffmpeg"] + process_args)

        flags = OrderedDict([])
        flags["-i"] = tmpfilename
        flags["-c:v"] = "libx264"
        flags["-crf"] = str(args.quality)
        flags["-pix_fmt"] = args.pixel_format
        flags["-preset"] = "veryslow"

        process_args = list(generate_args(flags))
        process_args.append(str(args.output))
        subprocess.run(["ffmpeg"] + process_args)


if __name__ == "__main__":
    sys.exit(main())

D xdg/user-dirs.dirs => xdg/user-dirs.dirs +0 -15
@@ 1,15 0,0 @@
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
# 
XDG_DESKTOP_DIR="$HOME/desktop"
XDG_DOWNLOAD_DIR="$HOME/download"
XDG_TEMPLATES_DIR="$HOME/template"
XDG_PUBLICSHARE_DIR="$HOME/public"
XDG_DOCUMENTS_DIR="$HOME/doc"
XDG_MUSIC_DIR="$HOME/media/audio"
XDG_PICTURES_DIR="$HOME/media/image"
XDG_VIDEOS_DIR="$HOME/media/video"

D xdg/user-dirs.locale => xdg/user-dirs.locale +0 -1
@@ 1,1 0,0 @@
en_US