automate/020_zfs_httm.sh

126 lines
3.5 KiB
Bash

#!/usr/bin/env bash
DEST=${1:-/etc/skel}
set -x
URL=raw.githubusercontent.com/
USER=kimono-koans
APP="httm"
KEY="${USER}.gpg"
packages="httm"
echo "deb [signed-by=/etc/apt/trusted.gpg.d/${KEY}] https://${URL}/${USER}/ppa/main ./" | sudo tee /etc/apt/sources.list-available/${APP}-ppa.list
echo "deb-src [signed-by=/etc/apt/trusted.gpg.d/${KEY}] https://${URL}/${USER}/ppa/main ./" | sudo tee -a /etc/apt/sources.list-available/${APP}-ppa.list
sudo ln -sf /etc/apt/sources.list-available/${APP}-ppa.list /etc/apt/sources.list.d/${APP}-ppa.list
# Bypass apt-proxy for ${APP} packages
if [ -d /etc/apt/apt.conf.d/02proxy ]; then
if [ "$(grep -q ${URL})" ]; then
echo "Acquire::http::Proxy { \"${URL}\" DIRECT; };" >> /etc/apt/apt.conf.d/02proxy
fi
else
echo "Acquire::http::Proxy { \"${URL}\" DIRECT; };" >> /etc/apt/apt.conf.d/02proxy
fi
# broken "moved permanently"
# curl -s --compressed https://${URL}/${USER}/ppa/main/KEY.gpg | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/${KEY} >/dev/null
sudo apt update
sudo apt install -y --no-install-recommends "$packages"
# httm --install-zsh-hot-keys puts a file in ${HOME} and includes it in the .zshrc
# we put in the zshrc.d instead.
# httm/scripts/httm-key-bindings.zsh
cat <<"EOF" | sudo tee "${DEST}/.zshrc.d/008_httm-key-bindings.zsh"
# ___ ___ ___ ___
# /\__\ /\ \ /\ \ /\__\
# /:/ / \:\ \ \:\ \ /::| |
# /:/__/ \:\ \ \:\ \ /:|:| |
# /::\ \ ___ /::\ \ /::\ \ /:/|:|__|__
# /:/\:\ /\__\ /:/\:\__\ /:/\:\__\ /:/ |::::\__\
# \/__\:\/:/ / /:/ \/__/ /:/ \/__/ \/__/~~/:/ /
# \::/ / /:/ / /:/ / /:/ /
# /:/ / \/__/ \/__/ /:/ /
# /:/ / /:/ /
# \/__/ \/__/
#
# Copyright (c) 2023, Robert Swinford <robert.swinford<...at...>gmail.com>
#
# For the full copyright and license information, please view the LICENSE file
# that was distributed with this source code.
# ALT-d - Dynamically snap selected files's dataset
__httm-snapshot() {
command httm --snap 2>/dev/null "$1" || \
command sudo httm --snap "$1" || \
echo "httm snapshot widget quit with a snapshot error. Check you have the correct permissions to snapshot."; return 1
local ret=$?
echo
return $ret
}
httm-snapshot-widget() {
local input_file
local canonical_path
# requires an fzf function sourced to work properly
if [[ $( type "__fsel" 2>/dev/null | grep -q "function" ) -eq 0 ]]
then
# need canonical path for a httm snapshot
input_file="$(__fsel)"
[[ -z "$input_file" ]] || canonical_path="$(readlink -f $input_file)"
else
canonical_path="$PWD"
fi
[[ -z "$canonical_path" ]] || __httm-snapshot "$filename"
local ret=$?
zle reset-prompt
return $ret
}
zle -N httm-snapshot-widget
bindkey '\ed' httm-snapshot-widget
# ALT-m - browse for ZFS snapshots interactively
httm-lookup-widget() {
echo
command httm -r -R
local ret=$?
zle reset-prompt
return $ret
}
zle -N httm-lookup-widget
bindkey '\em' httm-lookup-widget
# ALT-s - select files on ZFS snapshots interactively
__httm-select() {
command httm -s -R | \
while read item; do
echo -n "${item}"
done
local ret=$?
echo
return $ret
}
httm-select-widget() {
LBUFFER="${LBUFFER}$(__httm-select)"
local ret=$?
zle reset-prompt
return $ret
}
zle -N httm-select-widget
bindkey '\es' httm-select-widget%
EOF