dotfiles/config/scripts/bsh

62 lines
1.9 KiB
Plaintext
Raw Normal View History

2020-05-25 09:05:56 +02:00
#!/usr/bin/env bash
# TODO Do not dupplicate trimmed.bash
CACHE_DIR="${XDG_CACHE_DIR:-$HOME/.cache}/bsh"
FOLDER_NAME="geoffrey"
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}"
rm -rf "$WORK" # DEBUG
mkdir "$WORK"
# Copying files
2020-05-30 12:07:23 +02:00
grep -o '^[^#]*' ~/.config/shell/trimmed.bash > "${WORK}/.bashrc"
grep -o '^[^#]*' ~/.config/inputrc > "${WORK}/.inputrc"
grep -o '^[^"]*' ~/.config/vim/vimconfig.vim > "${WORK}/.vimrc"
#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
2020-05-25 09:05:56 +02:00
# Extra configuration
echo "alias s='sudo -s -E bash --rcfile ${DEST}/.bashrc'" >> "${WORK}/.bashrc"
echo "export VIMINIT='source ${DEST}/.vimrc'" >> "${WORK}/.bashrc"
#echo "export TERMINFO=${DEST}/terminfo" >> "${WORK}/.bashrc"
2020-05-25 09:05:56 +02:00
echo "export INPUTRC=${DEST}/.inputrc" >> "${WORK}/.bashrc"
# TODO Maybe we should just set HOME there…
# Crafting command
b64="$(cd "$CACHE_DIR"; tar czf - "$FOLDER_NAME" | base64 -w 0)"
echo "echo '$b64' | base64 -d | tar xzf - -C /tmp" > "${CACHE_DIR}/cmd"
echo "bash --rcfile ${DEST}/.bashrc" >> "${CACHE_DIR}/cmd"
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"
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")"