From ea0e9c7902663251b46e444331e7cdbac8919b4c Mon Sep 17 00:00:00 2001 From: Ryan Chan Date: Tue, 7 Dec 2021 00:04:44 +0000 Subject: [PATCH] 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 --- bash/.bash_profile | 1 - bin/backup-host | 13 +------- bin/connect-barrier | 3 ++ bin/screencap | 77 ++++++++++++++++++++++++++++++++++++++++++++ xdg/user-dirs.dirs | 15 --------- xdg/user-dirs.locale | 1 - 6 files changed, 81 insertions(+), 29 deletions(-) create mode 100755 bin/connect-barrier create mode 100755 bin/screencap delete mode 100644 xdg/user-dirs.dirs delete mode 100644 xdg/user-dirs.locale diff --git a/bash/.bash_profile b/bash/.bash_profile index 99c7dc6..ff51adf 100644 --- a/bash/.bash_profile +++ b/bash/.bash_profile @@ -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 diff --git a/bin/backup-host b/bin/backup-host index 08a7308..2d823f0 100755 --- a/bin/backup-host +++ b/bin/backup-host @@ -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_() { diff --git a/bin/connect-barrier b/bin/connect-barrier new file mode 100755 index 0000000..4709f55 --- /dev/null +++ b/bin/connect-barrier @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +barrierc --no-tray "$@" & +setxkbmap -device "$(xinput list --id-only "Virtual core XTEST keyboard")" "gb" diff --git a/bin/screencap b/bin/screencap new file mode 100755 index 0000000..cdbe928 --- /dev/null +++ b/bin/screencap @@ -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()) diff --git a/xdg/user-dirs.dirs b/xdg/user-dirs.dirs deleted file mode 100644 index 0129169..0000000 --- a/xdg/user-dirs.dirs +++ /dev/null @@ -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" diff --git a/xdg/user-dirs.locale b/xdg/user-dirs.locale deleted file mode 100644 index 7741b83..0000000 --- a/xdg/user-dirs.locale +++ /dev/null @@ -1 +0,0 @@ -en_US -- 2.45.2