From 41935c352cc31ec7e80a238d63bb97a5f86522ed Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Tue, 12 Dec 2023 18:24:59 +0100 Subject: [PATCH] Add terminal log using asciinema --- .bin/asciinema-log | 18 ++++++++++++++++++ .config/aliasrc | 1 + .config/env.d/99-local##hostname.portalo | 1 + .config/home-manager/common.nix | 1 + .config/zsh/.zshrc | 2 ++ 5 files changed, 23 insertions(+) create mode 100755 .bin/asciinema-log diff --git a/.bin/asciinema-log b/.bin/asciinema-log new file mode 100755 index 0000000..4062020 --- /dev/null +++ b/.bin/asciinema-log @@ -0,0 +1,18 @@ +#!/usr/bin/env sh + +set -e + +if [ -x "$(command -v asciinema)" ] \ + && [ -z "$ASCIINEMA_REC" ] \ + && [ "$ASCIINEMA_LOG" -gt 0 ] +then + ASCIINEMA_LOG_DIR="$HOME/.cache/logs" + mkdir -p "$ASCIINEMA_LOG_DIR" + _file_name_date=$(date +%Y-%m-%d_%H%M%S) + export ASCIINEMA_LOG_FILE="$ASCIINEMA_LOG_DIR/asciinema-$_file_name_date.txt" + asciinema rec --quiet --raw "$ASCIINEMA_LOG_FILE" + + exit 0 # Parent script should exit +fi + +exit 1 # Parent script should not exit diff --git a/.config/aliasrc b/.config/aliasrc index b3c2e47..b15fdca 100644 --- a/.config/aliasrc +++ b/.config/aliasrc @@ -7,6 +7,7 @@ alias aliases='$EDITOR ~/.config/aliasrc && . ~/.config/aliasrc' alias aliases.local='$EDITOR ~/.config/aliasrc.local && . ~/.config/aliasrc' # shellcheck disable=2154 alias arch-deps2deps='set -a; source PKGBUILD; set +a; paru -S --asdeps --noconfirm $depends && paru -Ui --rebuild' +alias asciinema-clear-log='if [ -f "$ASCIINEMA_LOG_FILE" ]; then \rm -v "$ASCIINEMA_LOG_FILE"; else echo "No log file found"; fi' alias bspwm-default='echo "default" > /tmp/bspwm_mode; bspc wm -r' alias bspwm-present='echo "presenter" > /tmp/bspwm_mode; bspc wm -r' diff --git a/.config/env.d/99-local##hostname.portalo b/.config/env.d/99-local##hostname.portalo index 087b50a..2f6100f 100755 --- a/.config/env.d/99-local##hostname.portalo +++ b/.config/env.d/99-local##hostname.portalo @@ -1,6 +1,7 @@ #!/bin/sh export AUTOSTART_DISPLAY="Hyprland" +export ASCIINEMA_LOG="1" export MONITOR_PRIMARY="DisplayPort-0" export MONITOR_SECONDARY="HDMI-A-0" diff --git a/.config/home-manager/common.nix b/.config/home-manager/common.nix index 1f75989..aba0b67 100644 --- a/.config/home-manager/common.nix +++ b/.config/home-manager/common.nix @@ -3,6 +3,7 @@ { # Packages that should be installed to the user profile. home.packages = with pkgs; [ + asciinema # tool to record terminal sessions bat # cat-alternative direnv # tool to load custom environments docker-credential-helpers diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 894a18d..33f3e63 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -122,3 +122,5 @@ source source-remote-file \ [ -x "$(command -v direnv)" ] && eval "$(direnv hook zsh)" [ -x "$(command -v starship)" ] && eval "$(starship init zsh)" + +asciinema-log && exit