init checkin
This commit is contained in:
parent
7a87842c47
commit
8dd0abb090
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
||||
Copyright (c) <year> <owner>. All rights reserved.
|
||||
Copyright (c) 2022 Luke Tidd. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
|
119
bashrc
Normal file
119
bashrc
Normal file
@ -0,0 +1,119 @@
|
||||
# If not running interactively, don't do anything
|
||||
[[ -z "$PS1" ]] && return
|
||||
[[ $- == *i* ]] && stty -ixon
|
||||
|
||||
####
|
||||
# settings
|
||||
set -o vi
|
||||
shopt -s checkwinsize # update the values of LINES and COLUMNS.
|
||||
shopt -s nullglob
|
||||
bind 'set enable-bracketed-paste off'
|
||||
LANG="en_US.UTF-8"
|
||||
LC_COLLATE="en_US.UTF-8"
|
||||
LC_CTYPE="en_US.UTF-8"
|
||||
LC_MESSAGES="en_US.UTF-8"
|
||||
LC_MONETARY="en_US.UTF-8"
|
||||
LC_NUMERIC="en_US.UTF-8"
|
||||
LC_TIME="en_US.UTF-8"
|
||||
LC_ALL=
|
||||
GDK_BACKEND=wayland
|
||||
|
||||
####
|
||||
# paths
|
||||
function in_path() {
|
||||
new_path="$1"
|
||||
a=0
|
||||
while true; do
|
||||
a=$((a+1))
|
||||
current="$(cut -d: -f"${a}" <<< "$PATH")"
|
||||
if [[ -z "$current" ]]; then
|
||||
return 1
|
||||
fi
|
||||
if [[ "$new_path" == "$current" ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
}
|
||||
unset additional_paths
|
||||
declare -a additional_paths
|
||||
additional_paths=(
|
||||
"${HOME}/bin"
|
||||
"${HOME}/bin2"
|
||||
"${HOME}/go/bin"
|
||||
"${HOME}/local/bin"
|
||||
"${HOME}/.cargo/bin"
|
||||
"${HOME}/git/cr/depot_tools"
|
||||
"/usr/local/go/bin/"
|
||||
)
|
||||
for path in "${additional_paths[@]}"; do
|
||||
in_path "$path" || PATH="${path}:${PATH}"
|
||||
done
|
||||
unset additional_paths
|
||||
unset in_path
|
||||
|
||||
####
|
||||
# sources
|
||||
unset sources
|
||||
declare -a sources
|
||||
sources=(
|
||||
"${HOME}/.bash_aliases"
|
||||
"${HOME}/.bash_functions"
|
||||
"${HOME}/.bash_functions2"
|
||||
"${HOME}/.cargo/env"
|
||||
"${KITTY_INSTALLATION_DIR}/shell-integration/bash/kitty.bash"
|
||||
)
|
||||
|
||||
for source in "${sources[@]}"; do
|
||||
if [[ -r "${source}" ]]; then
|
||||
. "${source}"
|
||||
fi
|
||||
done
|
||||
unset sources
|
||||
|
||||
if [[ -d "${HOME}/.config/aliases" ]]; then
|
||||
readarray -d '' bash_sources < <(find "${HOME}/.config/aliases" -type f | sort -V | tr '\n' '\0')
|
||||
for source in "${bash_sources[@]}"; do
|
||||
. "$source"
|
||||
done
|
||||
fi
|
||||
|
||||
####
|
||||
# env
|
||||
export HISTCONTROL=ignoredups
|
||||
export HISTCONTROL=ignoreboth
|
||||
export PS1='$ '
|
||||
export VISUAL=vim
|
||||
export EDITOR="$VISUAL"
|
||||
export SYSTEMD_PAGER="cat"
|
||||
export GIT_PAGER="cat"
|
||||
export XDG_CONFIG_HOME="${HOME}/.config"
|
||||
export XDG_CURRENT_DESKTOP=sway
|
||||
export MOZ_ENABLE_WAYLAND=1
|
||||
|
||||
case "$TERM" in
|
||||
screen-256color) export PS1='\[\033[1;35m\]\d \t ${debian_chroot:+($debian_chroot)}\[\033[0;55m\]\H\[\033[00m\]:\[\033[01;55m\]\w\[\033[00m\]\n\$ ' && alias ls='ls --color=auto';;
|
||||
esac
|
||||
|
||||
##############################
|
||||
# ssh auth sock
|
||||
auth_sock_dir="${HOME}/.config/ssh"
|
||||
auth_sock_log="/tmp/ssh_auth_sock"
|
||||
if [[ ! -d "$auth_sock_dir" ]]; then
|
||||
mkdir -p "$auth_sock_dir"
|
||||
fi
|
||||
ssh_auth_link="${auth_sock_dir}/ssh_auth_sock"
|
||||
pgrep ssh-agent &>/dev/null
|
||||
if [[ "$?" == "1" ]]; then
|
||||
eval "$(ssh-agent &>"$auth_sock_log")"
|
||||
if [[ -L "$ssh_auth_link" ]]; then
|
||||
rm "$ssh_auth_link"
|
||||
fi
|
||||
if [[ -z "$SSH_AUTH_SOCK" ]]; then
|
||||
printf 'Something went wrong with ssh-agent:\n' >&2
|
||||
cat "$auth_sock_log" >&2
|
||||
else
|
||||
ln -s "$SSH_AUTH_SOCK" "$ssh_auth_link"
|
||||
fi
|
||||
else
|
||||
[[ -L "${ssh_auth_link}" ]] && [[ -e "${ssh_auth_link}" ]] && export SSH_AUTH_SOCK="$ssh_auth_link"
|
||||
fi
|
128
tmux_control
Executable file
128
tmux_control
Executable file
@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function link_or_rm() {
|
||||
local env="$1"
|
||||
local tmp="$2"
|
||||
if [[ -z "${env}" ]]; then
|
||||
# No auth sock; remove symlink, if any.
|
||||
rm -f -- "${tmp}"
|
||||
elif [[ "${env}" != "${tmp}" ]]; then
|
||||
# Construct expected symlink to point to auth sock.
|
||||
ln -snf -- "${env}" "${tmp}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Get invocation, stx or mtx
|
||||
zero="$0"
|
||||
invocation=$(basename "$zero")
|
||||
|
||||
case "$invocation" in
|
||||
tmux_control)
|
||||
declare -a tmux_links
|
||||
tmux_links=( stx mtx sx mx tls )
|
||||
for link in "${tmux_links[@]}"; do
|
||||
if [[ ! -h "${HOME}/bin/${link}" ]]; then
|
||||
ln -s "${HOME}/bin/tmux_control" "${HOME}/bin/${link}"
|
||||
fi
|
||||
done
|
||||
echo 'stx or sx for inner sessions; mtx or mx for outer sessions, tls to list all sessions' >&2
|
||||
exit 1
|
||||
;;
|
||||
sx)
|
||||
socket="tmux_${USER}_stx"
|
||||
tmux -L "${socket}" "$@"
|
||||
exit $?
|
||||
;;
|
||||
mx)
|
||||
socket="tmux_${USER}_mtx"
|
||||
tmux -L "${socket}" "$@"
|
||||
exit $?
|
||||
;;
|
||||
tls)
|
||||
declare -a sockets
|
||||
readarray -d '' sockets < <(find "/tmp/tmux-$(id -u)" -maxdepth 1 -type s -print0)
|
||||
for socket in ${sockets[*]}; do
|
||||
printf '%s\n' "$socket"
|
||||
tmux -L "${socket}" list-sessions | sed 's/^/ /'
|
||||
done
|
||||
exit 0
|
||||
esac
|
||||
|
||||
socket="tmux_${USER}_${invocation}"
|
||||
|
||||
style="inner"
|
||||
if [[ "${invocation}" == mtx ]]; then
|
||||
style="outer"
|
||||
fi
|
||||
|
||||
config="${HOME}/.tmux.conf_${style}"
|
||||
|
||||
session_name="default"
|
||||
if [[ -n $1 ]]; then
|
||||
session_name="$1"
|
||||
fi
|
||||
|
||||
if [[ "$1" == "test" ]]; then
|
||||
echo "invocation: ${invocation}"
|
||||
echo "config: ${config}"
|
||||
echo "session: ${session_name}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ ! -f "${config}" ]]; then
|
||||
echo "Didn't find ${config}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make the temp directory if it doesn't exist
|
||||
home_sock_folder="${HOME}/.tmp"
|
||||
if ! [ -d "${home_sock_folder}" ]; then
|
||||
mkdir -m 700 "${home_sock_folder}"
|
||||
fi
|
||||
|
||||
# Symlinks to sockets that might change out from under tmux
|
||||
if [[ -z "${TMUX}" ]] || [[ "$style" == "inner" && "$TMUX" =~ mtx ]]; then
|
||||
ssh_auth_sock_symlink="${home_sock_folder}/ssh_auth_sock"
|
||||
fwd_ssh_sock_symlink="${home_sock_folder}/fwd_ssh_auth_sock"
|
||||
sway_sock_symlink="${home_sock_folder}/sway_sock"
|
||||
i3_sock_symlink="${home_sock_folder}/i3_sock"
|
||||
link_or_rm "${SSH_AUTH_SOCK}" "${ssh_auth_sock_symlink}"
|
||||
link_or_rm "${FWD_SSH_AUTH_SOCK}" "${fwd_ssh_sock_symlink}"
|
||||
# SWAYSOCK == I3SOCK, probably some Xwayland compatability thing
|
||||
link_or_rm "${SWAYSOCK}" "${sway_sock_symlink}"
|
||||
link_or_rm "${SWAYSOCK}" "${i3_sock_symlink}"
|
||||
|
||||
# See if there are any sessions on this socket
|
||||
echo running: tmux -L "${socket}" list-sessions
|
||||
tmux -L "${socket}" list-sessions
|
||||
echo results: $?
|
||||
if [[ $? != 0 ]]; then
|
||||
# No tmux session @ $socket
|
||||
exec env \
|
||||
I3SOCK="${i3_sock_symlink}" \
|
||||
SWAYSOCK="${sway_sock_symlink}" \
|
||||
SSH_AUTH_SOCK="${ssh_auth_sock_symlink}" \
|
||||
FWD_SSH_AUTH_SOCK="${f}" \
|
||||
tmux -f "${config}" -L "${socket}" ${args} new-session -s "${session_name}"
|
||||
|
||||
elif tmux -L "${socket}" list-sessions 2>/dev/null | grep "^${session_name}:" &>/dev/null; then
|
||||
# A named session exists
|
||||
exec env \
|
||||
I3SOCK="${i3_sock_symlink}" \
|
||||
SWAYSOCK="${sway_sock_symlink}" \
|
||||
SSH_AUTH_SOCK="${ssh_auth_sock_symlink}" \
|
||||
FWD_SSH_AUTH_SOCK="${f}" \
|
||||
tmux -f "${config}" -L "${socket}" ${args} attach -t "${session_name}"
|
||||
else
|
||||
# Some session lives at that socket but it's a different name than is given
|
||||
exec env \
|
||||
I3SOCK="${i3_sock_symlink}" \
|
||||
SWAYSOCK="${sway_sock_symlink}" \
|
||||
SSH_AUTH_SOCK="${ssh_auth_sock_symlink}" \
|
||||
FWD_SSH_AUTH_SOCK="${f}" \
|
||||
tmux -f "${config}" -L "${socket}" ${args} new-session -s "${session_name}"
|
||||
fi
|
||||
else
|
||||
echo "Already in a tmux session. Giving up."
|
||||
exit 1
|
||||
fi
|
Loading…
x
Reference in New Issue
Block a user