linux-config/files/dotfiles/shellconfig/common.sh

133 lines
3.2 KiB
Bash
Raw Normal View History

2021-10-22 11:45:20 +00:00
#!/bin/bash
########################################################
# DO NOT EDIT - WILL BE DISCARDED IN NEXT PLAYBOOK RUN #
########################################################
############################################
# Shell aliases
############################################
alias :q=exit
2021-12-09 08:36:10 +00:00
alias :Q=exit
2021-10-22 11:45:20 +00:00
alias ls='lsd'
alias f='printf "\033c"'
alias cat=bat
2021-12-09 08:36:10 +00:00
alias t=tmux
2021-10-22 11:45:20 +00:00
############################################
# Environment Variables
############################################
# bat theme (New cat) $ bat --list-themes
gruvbox="gruvbox"
monokai="Monokai Extended"
nord="Nord"
export BAT_THEME="$nord"
export VISUAL=vim;
export EDITOR=vim;
############################################
# Shell functions
############################################
function pre_check_tmux_for_layout() {
ERROR_PREFIX="[ERROR]: "
if [[ -z $(which tmux) ]]; then
echo ""
echo "$ERROR_PREFIX Missing dependencie of tmux";
echo ""
return 1
fi
if [[ -z ${TMUX-} ]];then
echo ""
echo "$ERROR_PREFIX Must run in a tmux session";
echo ""
return 1
fi
if [ $(tmux list-panes | wc -l) -ne 1 ]; then
echo ""
echo "$ERROR_PREFIX Please run '$1' in a clean tmux window (No panes)"
echo ""
return 1
fi
}
# Creates a tmux layout of 3 columns with mid col has a vertical split for use as well
# Usage: $ ide
# $ ide name_for_workspace
function ide() {
CURRENT_DIR=$(echo "${PWD##*/}")
IDE_NAME="[⌨️ IDE: ${1:=$CURRENT_DIR}]"
pre_check_tmux_for_layout "ide" || return 1
tmux send-keys "l" C-m
tmux split-window -h -p 80
tmux split-window -h -p 30
tmux send-keys "lazygit" C-m
tmux select-pane -t 1
tmux split-window -v -p 20
tmux select-pane -t 1
tmux send-keys "vim" C-m
tmux rename-window ${IDE_NAME}
}
# Create a tmux grid layout. default 2x2
# Usage: $ grid
# $ grid 3x3
function grid() {
#WIP
pre_check_tmux_for_layout "grid" || return 1
INPUT=${1:=0x0}
GRID_COLS=$(echo $INPUT | grep -oP '^[\d]+')
GRID_ROWS=$(echo $INPUT | grep -oP '[\d]+$')
echo "COLS: $GRID_COLS"
echo "ROWS: $GRID_ROWS"
if [[ $GRID_ROWS == "0" ]] || [[ $GRID_COLS == "0" ]]; then
echo "Defaulting to 2x2 grid"
GRID_COLS="2"
GRID_ROWS="2"
fi
V_PANES=$((GRID_ROWS))
H_PANES=$((GRID_COLS))
V_RATIO=$((100 / V_PANES))
H_RATIO=$((100 / H_PANES))
echo "COLS: $GRID_COLS"
echo "ROWS: $GRID_ROWS"
for h in {1..$((H_PANES - 1))}
do
H_SIZE=$((100 - (h * H_RATIO)))
tmux split-window -h -p $((H_SIZE))
echo " $h H_SIZE $H_SIZE"
done
for cell in {$((H_PANES - 1))..0}
do
tmux select-pane -t ${cell}
CURRENT_PANE=$(tmux list-panes | grep '(active)$' | grep -oP '^[\d]+')
echo Current pane: $CURRENT_PANE
for v in {1..$((V_PANES - 1))}
do
V_SIZE=$((100 - (v * V_RATIO)))
tmux split-window -v -p $((V_SIZE))
echo " $v V_SIZE $V_SIZE"
done
done
# Select top left cell (Starting point)
tmux select-pane -t 0
}
2021-10-22 11:45:20 +00:00