dotfiles/config/scripts/bsh

69 lines
2.3 KiB
Plaintext
Raw Normal View History

2020-05-25 09:05:56 +02:00
#!/usr/bin/env bash
# TODO More integrated with current config
2020-05-25 09:05:56 +02:00
CACHE_DIR="${XDG_CACHE_DIR:-$HOME/.cache}/bsh"
FOLDER_NAME="geoffrey"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
2020-05-25 09:05:56 +02:00
mkdir -p "$CACHE_DIR"
2020-05-30 12:07:23 +02:00
if [ ! -f "${CACHE_DIR}/cmd" ]
2020-05-25 09:05:56 +02:00
then
# Preparation
WORK="${CACHE_DIR}/${FOLDER_NAME}"
DEST="/tmp/${FOLDER_NAME}"
mkdir "$WORK"
# TODO Maybe we should just set HOME there…
# Bashrc generation (sortable then unsortable)
grep -o '^\s*[^#]*' $SCRIPT_DIR/.bsh/bashrc | sed 's/^\s\+//' > "${WORK}/b"
echo "alias s='sudo -s -E bash --rcfile ${DEST}/b'" >> "${WORK}/b"
echo "export VIMINIT='source ${DEST}/v'" >> "${WORK}/b"
#echo "export TERMINFO=${DEST}/terminfo" >> "${WORK}/b"
echo "export INPUTRC=${DEST}/i" >> "${WORK}/b"
# Sort for compression efficiency (saves a whooping 12 bytes)
sort -u "${WORK}/b" > "${WORK}/b_sorted"
mv "${WORK}/b_sorted" "${WORK}/b"
dircolors --sh >> "${WORK}/b"
grep -o '^[^#]*' $SCRIPT_DIR/.bsh/bashrc_unsortable | sed 's/^\s\+//' >> "${WORK}/b"
# Other files generation
#mkdir -p "${WORK}/terminfo/${TERM:0:1}"
#if [ -f "/usr/share/terminfo/${TERM:0:1}/${TERM}" ]
#then
# cp "/usr/share/terminfo/${TERM:0:1}/${TERM}" "${WORK}/terminfo/${TERM:0:1}/${TERM}"
#elif [ -f "$HOME/.config/terminfo/${TERM:0:1}/${TERM}" ]
#then
# cp "$HOME/.config/terminfo/${TERM:0:1}/${TERM}" "${WORK}/terminfo/${TERM:0:1}/${TERM}"
#fi
grep -o '^\s*[^#]*' $SCRIPT_DIR/.bsh/inputrc | sed 's/^\s\+//' > "${WORK}/i"
grep -o '^\s*[^"]*' $SCRIPT_DIR/.bsh/vimrc | sed 's/^\s\+//' > "${WORK}/v"
2020-05-25 09:05:56 +02:00
# Crafting command
b64="$(cd "$CACHE_DIR"; tar czf - "$FOLDER_NAME" | base64 -w 0)"
echo "echo $b64|base64 -d|tar xzC /tmp" > "${CACHE_DIR}/cmd"
echo "bash --rcfile ${DEST}/b" >> "${CACHE_DIR}/cmd"
2020-05-25 09:05:56 +02:00
echo "rm -rf ${DEST}" >> "${CACHE_DIR}/cmd"
2020-05-30 12:07:23 +02:00
# TODO Do not remove unless last one connected
2020-05-25 09:05:56 +02:00
# Cleanup
rm -rf "$WORK"
2020-05-25 09:05:56 +02:00
fi
2021-07-04 11:48:00 +02:00
# To keep until https://github.com/openssh/openssh-portable/commit/f64f8c00d158acc1359b8a096835849b23aa2e86
# is merged
function _ssh {
if [ "${TERM}" = "alacritty" ]
then
TERM=xterm-256color ssh "$@"
else
ssh "$@"
fi
}
alias ssh='_ssh'
_ssh -t "$@" "$(cat "${CACHE_DIR}/cmd")"