mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-12-11 09:22:02 +01:00
113 lines
3 KiB
Bash
113 lines
3 KiB
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
|
||
|
#
|
||
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||
|
|
||
|
[[ -e /etc/profile.d/nix.sh ]] && . /etc/profile.d/nix.sh
|
||
|
|
||
|
# If not running interactively, don't do anything
|
||
|
[[ $- != *i* ]] && return
|
||
|
|
||
|
[[ $DISPLAY ]] && shopt -s checkwinsize
|
||
|
|
||
|
[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion
|
||
|
|
||
|
## Enable color on grep
|
||
|
alias grep='grep --color=auto'
|
||
|
|
||
|
## Replace ls and cat with exa and bat respectively
|
||
|
alias ls='@exa@/bin/exa'
|
||
|
alias cat='@bat@/bin/bat'
|
||
|
|
||
|
if [ -z "${SHLVL_INIT+x}" ]; then
|
||
|
export SHLVL_INIT=1 SHLVL=1
|
||
|
fi
|
||
|
|
||
|
|
||
|
if [ "$SHLVL" = 1 ]; then
|
||
|
export PS1="\u@\[\e[37m\]\h\[\e[m\]:\[\e[32m\]\w\[\e[m\]\[\e[31m\]\\$\[\e[m\] "
|
||
|
else
|
||
|
export PS1="$SHLVL: \u@\[\e[37m\]\h\[\e[m\]:\[\e[32m\]\w\[\e[m\]\[\e[31m\]\\$\[\e[m\] "
|
||
|
fi
|
||
|
|
||
|
emacsclient() {
|
||
|
if [[ -e "$HOME/.ssh/emacs-server" ]] && \
|
||
|
nc -Uz "$HOME/.ssh/emacs-server" >/dev/null 2>&1 && \
|
||
|
[[ ! -z ${INSIDE_EMACS+x} ]] ; then
|
||
|
params=()
|
||
|
sudo=0
|
||
|
nowait=0
|
||
|
|
||
|
host=$(echo $SSH_CONNECTION | cut -d' ' -f3)
|
||
|
port=$(echo $SSH_CONNECTION | cut -d' ' -f4)
|
||
|
|
||
|
for p in "${@}"; do
|
||
|
if [[ "${p}" == "-s" || "${p}" == "--sudo" ]]; then
|
||
|
sudo=1
|
||
|
elif [[ "${p}" == "-n" || "${p}" == "--no-wait" ]]; then
|
||
|
params+=( "-nowait" )
|
||
|
else
|
||
|
if [[ ${sudo} -eq 1 ]]; then
|
||
|
params+=( "-file /ssh:${USER}@${host}#${port}|sudo::"$(realpath -m "${p}") )
|
||
|
else
|
||
|
params+=( "-file /ssh:${USER}@${host}#${port}:"$(realpath "${p}") )
|
||
|
fi
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
if [[ ${nowait} -eq 0 ]] ; then
|
||
|
printf 'Waiting for Emacs...\n'
|
||
|
fi
|
||
|
|
||
|
echo "${params[@]}" | nc -U "$HOME/.ssh/emacs-server" >/dev/null 2>&1
|
||
|
else
|
||
|
sudo=0
|
||
|
args=()
|
||
|
for p in "${@}"; do
|
||
|
if [[ "${p}" == "-s" || "${p}" == "--sudo" ]]; then
|
||
|
sudo=1
|
||
|
else
|
||
|
args+=( "${p}" )
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
if [[ ${sudo} -eq 1 ]]; then
|
||
|
echo env emacsclient "/sudo::${args[0]}" "${args[@]:1}"
|
||
|
env emacsclient "/sudo::${args[0]}" "${args[@]:1}"
|
||
|
else
|
||
|
env emacsclient "${@}"
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
alias e='emacsclient'
|
||
|
alias E='emacsclient -s'
|
||
|
|
||
|
|
||
|
## Set prompt
|
||
|
|
||
|
export EDITOR="emacsclient"
|
||
|
export BROWSER="firefox-nightly"
|
||
|
|
||
|
## Clear scrollback for vterm
|
||
|
if [[ "$INSIDE_EMACS" = 'vterm' ]]; then
|
||
|
function clear(){
|
||
|
vterm_printf "51;Evterm-clear-scrollback";
|
||
|
tput clear;
|
||
|
}
|
||
|
fi
|
||
|
|
||
|
if [[ "$INSIDE_EMACS" = 'vterm' ]] \
|
||
|
&& [[ -n ${EMACS_VTERM_PATH} ]] \
|
||
|
&& [[ -f ${EMACS_VTERM_PATH}/etc/emacs-vterm-bash.sh ]]; then
|
||
|
source ${EMACS_VTERM_PATH}/etc/emacs-vterm-bash.sh
|
||
|
fi
|
||
|
|
||
|
if [[ "@direnvEnabled@" == "true" ]] ; then
|
||
|
eval "$(direnv hook bash)"
|
||
|
fi
|
||
|
|
||
|
|
||
|
alias zlist="zfs list -r storfa -o name,used,avail,refer,:relmount,compression,compressratio,recordsize,snapdir"
|