Handle terminals better

This commit is contained in:
Diego Fernando Carrión 2024-08-07 16:10:36 +02:00
parent 1a886be02c
commit 19200291f9
4 changed files with 118 additions and 10 deletions

View File

@ -6,7 +6,34 @@
# If not running interactively, don't do anything # If not running interactively, don't do anything
[ -z "$PS1" ] && return [ -z "$PS1" ] && return
<<<<<<< HEAD
[ "$(tty)" = "/dev/ttyUSB0" ] && export TERM=vt220 [ "$(tty)" = "/dev/ttyUSB0" ] && export TERM=vt220
=======
case "$(tty)" in
/dev/ttyS*|/dev/ttyUSB*|/dev/ttyACM*|/dev/ttyAMA)
# Don't try to set the window title on serial ports
shopt -u checkwinsize
export TERM=vt220
;;
esac
limited_terminal() {
case $TERM in
*-color*|*-256color*)
return false
;;
*unicode*)
return false
;;
dumb|linux|hurd|vt*|mach*|wsvt*|tmux*|cons25*|rxvt*|screen*|sun)
return true
;;
*)
return false
;;
esac
}
>>>>>>> 9eb8244 (Handle terminals better)
# check the window size after each command and, if necessary, # check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS. # update the values of LINES and COLUMNS.

View File

@ -1,7 +1,3 @@
alias ls='ls --color=auto'
alias ll='ls -lh'
alias la='ls -A'
alias mv="mv -iv" alias mv="mv -iv"
alias cp="cp -riv" alias cp="cp -riv"
alias mkdir="mkdir -vp" alias mkdir="mkdir -vp"
@ -9,13 +5,52 @@ alias mkdir="mkdir -vp"
alias red_october="ping -c1" alias red_october="ping -c1"
alias ro="red_october" alias ro="red_october"
alias clipboard="xclip -selection c -i" if [ -n $DISPLAY ]
alias cb="clipboard" then
alias clipboard="xclip -selection c -i"
alias cb="clipboard"
fi
alias compose="less /usr/share/X11/locale/en_US.UTF-8/Compose" if [ -f /usr/share/X11/locale/en_US.UTF-8/Compose ]
then
alias compose_ref="less /usr/share/X11/locale/en_US.UTF-8/Compose"
fi
if [ -x "$(which nvim)" ] if [ -x "$(which nvim)" ]
then then
alias vim=nvim alias vim=nvim
alias vimdiff="nvim -d" alias vimdiff="nvim -d"
fi fi
if [ -x "$(command -v xdg-open)" ]
then
alias open="xdg-open"
fi
# cat && less
if [ ! limited_terminal && -x "$(command -v batcat)" ] || [ -x "$(command -v bat)" ]
then
if [ -x "$(command -v batcat)" ]
then
alias bat=batcat
fi
alias ccat="$(which cat)"
alias lless="$(which less)"
alias less=bat
alias cat=bat
fi
# ls
if [ ! limited_terminal ]
then
if [ -x "$(command -v lsd)" ]
then
alias lls="$(which ls)"
alias ls=lsd
else
alias ls='ls --color=auto'
fi
fi
alias la='ls -A'
alias ll='ls -lh'
alias lla='ls -lA'

View File

@ -7,3 +7,51 @@ function cll() {
cd $1 cd $1
ls -l ls -l
} }
function whence() {
# Usage:
# which_follow_links [-p] <command>
# -p: Print each symlink path
local follow_links=false
local print_links=false
# Option parsing
while getopts "p" opt; do
case $opt in
p)
print_links=true
;;
h)
tabs 2
echo "Usage:"
echo -e "\twhence [-p | -h] <command>"
echo -e "\t\t-h: Print Usage"
echo -e "\t\t-p: Print each symlink path"
tabs
return
;;
\?)
echo "Invalid option: -$OPTARG" >&2
return
;;
esac
done
shift $((OPTIND-1))
# Find the initial path using which
local path=$(which "$1" 2> /dev/null)
if [[ -z "$path" ]]; then
echo "$1 not found"
return
fi
# Follow symlinks
while [[ -L "$path" ]]; do
if [[ "$print_links" == "true" ]]; then
echo "Link: $path -> $(readlink -f "$path")"
fi
path=$(readlink -f "$path")
done
echo "Final target: $path"
}

View File

@ -82,10 +82,8 @@ prompt_cmd() {
echo echo
} }
if [ "$TERM" = "vt220" ] if [ ! limited_terminal ]
then then
echo > /dev/null
else
export PROMPT_COMMAND="prompt_cmd" export PROMPT_COMMAND="prompt_cmd"
export PS1="$PREFIX\[$(tput setaf $BASE_COLOR)\]\[$(tput bold)\][\[$(tput setaf 1)\]\u\[$(tput setaf $BASE_COLOR)\]@\h \[$(tput setaf 3)\]\W\[$(tput setaf $BASE_COLOR)\]]\[$(tput setaf 1)\]\\$ \[$(tput sgr0)\]" export PS1="$PREFIX\[$(tput setaf $BASE_COLOR)\]\[$(tput bold)\][\[$(tput setaf 1)\]\u\[$(tput setaf $BASE_COLOR)\]@\h \[$(tput setaf 3)\]\W\[$(tput setaf $BASE_COLOR)\]]\[$(tput setaf 1)\]\\$ \[$(tput sgr0)\]"
fi fi