made tmux nvim better?
This commit is contained in:
parent
7270ec8f92
commit
1551aa9dc2
1 changed files with 55 additions and 56 deletions
111
.bash_aliases
111
.bash_aliases
|
@ -27,11 +27,6 @@ command_exists() {
|
|||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||
command_exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# ─< Check if the user is root and set sudo variable if necessary >───────────────────────
|
||||
check_root() {
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
|
@ -170,15 +165,6 @@ _alias_() {
|
|||
alias lazygit="$HOME/go/bin/lazygit" &&
|
||||
alias lg="lazygit"
|
||||
|
||||
function y() {
|
||||
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
|
||||
yazi "$@" --cwd-file="$tmp"
|
||||
if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
|
||||
builtin cd -- "$cwd"
|
||||
fi
|
||||
rm -f -- "$tmp"
|
||||
}
|
||||
|
||||
# ─< cli explorer >───────────────────────────────────────────────────────────────────────
|
||||
if command_exists "$HOME/.cargo/bin/yazi"; then
|
||||
echo_info "yazi is the explorer of choice"
|
||||
|
@ -190,6 +176,16 @@ _alias_() {
|
|||
echo_info "lf is the explorer of choice"
|
||||
fi
|
||||
|
||||
# ─< yazi move when exit >────────────────────────────────────────────────────────────────
|
||||
function y() {
|
||||
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
|
||||
yazi "$@" --cwd-file="$tmp"
|
||||
if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
|
||||
builtin cd -- "$cwd"
|
||||
fi
|
||||
rm -f -- "$tmp"
|
||||
}
|
||||
|
||||
# ─< colorized ls >─────────────────────────────────────────────────────────────────────────
|
||||
if command_exists exa; then
|
||||
alias ls="exa --icons -l --git"
|
||||
|
@ -213,37 +209,6 @@ _alias_() {
|
|||
alias ll="ls --color=always -lph"
|
||||
fi
|
||||
|
||||
# ─< t stands for tmux >────────────────────────────────────────────────────────────────────
|
||||
if command_exists tmux; then
|
||||
local tmux_y="-- tmux-session active! | connecting to active session --"
|
||||
local tmux_n="-- no tmux-session found! | creating one --"
|
||||
ta() {
|
||||
command tmux list-sessions >/dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
if command_exists notify-send; then
|
||||
notify-send "TMUX" "$tmux_y"
|
||||
sleep 0.5
|
||||
tmux attach
|
||||
else
|
||||
echo_info "$tmux_y"
|
||||
sleep 0.5
|
||||
tmux attach
|
||||
fi
|
||||
else
|
||||
if command_exists notify-send; then
|
||||
notify-send "TMUX" "$tmux_n"
|
||||
sleep 0.5
|
||||
tmux
|
||||
else
|
||||
echo_info "$tmux_n"
|
||||
sleep 0.5
|
||||
tmux
|
||||
fi
|
||||
fi
|
||||
}
|
||||
alias ts="tmux source $HOME/.tmux.conf"
|
||||
fi
|
||||
|
||||
# ─< t stands for trash(-cli) >───────────────────────────────────────────────────────────────
|
||||
if command_exists trash; then
|
||||
alias rm="trash"
|
||||
|
@ -340,6 +305,51 @@ _alias_() {
|
|||
fi
|
||||
|
||||
alias inst_lazydocker="curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash"
|
||||
|
||||
# Function to determine which Neovim command to use
|
||||
choose_nvim() {
|
||||
if [ -n "$DISPLAY" ] || [ -n "$WAYLAND_DISPLAY" ]; then
|
||||
# If in a graphical environment, use Neovide
|
||||
if command_exists neovide; then
|
||||
echo "neovide --fork"
|
||||
return
|
||||
fi
|
||||
elif [ -n "$TMUX" ]; then
|
||||
# If inside an active tmux session, use nvim
|
||||
echo "command nvim"
|
||||
return
|
||||
fi
|
||||
# Default to nvim
|
||||
echo "command nvim"
|
||||
}
|
||||
|
||||
# Set up Neovim aliases based on environment
|
||||
if command_exists nvim; then
|
||||
alias cnvim="command nvim"
|
||||
alias nvim="$(choose_nvim)"
|
||||
|
||||
if [ -d "$HOME/.config/nvchad" ]; then
|
||||
alias nvchad='NVIM_APPNAME="nvchad" command nvim'
|
||||
alias neochad='NVIM_APPNAME="nvchad" neovide --fork'
|
||||
fi
|
||||
fi
|
||||
|
||||
# Tmux session manager
|
||||
if command_exists tmux; then
|
||||
ta() {
|
||||
if tmux list-sessions >/dev/null 2>&1; then
|
||||
echo "-- tmux session active! | Connecting to active session --"
|
||||
sleep 0.3
|
||||
tmux attach
|
||||
else
|
||||
echo "-- No tmux session found! | Creating one --"
|
||||
sleep 0.3
|
||||
tmux
|
||||
fi
|
||||
}
|
||||
|
||||
alias ts="tmux source $HOME/.tmux.conf"
|
||||
fi
|
||||
}
|
||||
|
||||
_coding_() {
|
||||
|
@ -363,17 +373,6 @@ _coding_() {
|
|||
alias code="$cursor_exe"
|
||||
fi
|
||||
|
||||
# ─< neovide, the best frontend for any neovim-config >───────────────────────────────────
|
||||
if command_exists nvim; then
|
||||
if command_exists neovide; then
|
||||
if [ -n "$TMUX" ]; then
|
||||
alias nvim="command nvim"
|
||||
else
|
||||
alias nvim="neovide --fork"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Function to get the IP address
|
||||
get_ip() {
|
||||
ip a | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d/ -f1 | head -n 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue