Initial commit - New Prompt
This commit is contained in:
commit
56dfeda5e7
|
@ -0,0 +1,28 @@
|
|||
# Bash Tools
|
||||
|
||||
Some Tools and convenient scripts to make using Console Life Better.
|
||||
These tools in this repo are made for global use. Folders Structure is
|
||||
kept to know where they must be copied in your system.
|
||||
|
||||
# How to install
|
||||
You will need sudo, as scripts are intended to be global
|
||||
|
||||
```
|
||||
# Get scripts
|
||||
git clone https://git.a-lec.org/echolib/bash-tools.git
|
||||
|
||||
# Copy scripts (example) in the global profile folder
|
||||
sudo cp ~/bash_tools/etc/profile.d/* /etc/profile.d/
|
||||
```
|
||||
|
||||
As bash scripts, you will have to manually edit /etc/bash.bashrc and
|
||||
add - according to your needs - a load script line
|
||||
|
||||
```
|
||||
# Change Prompt with this one
|
||||
[[ -f /etc/profile.d/prompt.sh ]] && . /etc/profile.d/prompt.sh
|
||||
```
|
||||
|
||||
# ToDo ?
|
||||
There will be a lot more to come soon. Maybe then, i will create a setup
|
||||
to help you install what you need.
|
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
|
@ -0,0 +1,99 @@
|
|||
#!/bin/bash
|
||||
_ps1__refresh_history() {
|
||||
history -n
|
||||
history -w
|
||||
history -c
|
||||
history -r
|
||||
|
||||
tac "$HISTFILE" \
|
||||
| awk '!x[$0]++' \
|
||||
> /tmp/refreshprompt \
|
||||
&& tac /tmp/refreshprompt \
|
||||
> "$HISTFILE"
|
||||
|
||||
rm /tmp/refreshprompt
|
||||
}
|
||||
|
||||
# Adding new blank line for readability
|
||||
_ps1__pre_prompt_blankline() {
|
||||
IFS=';' read -sdR -p $'\E[6n' ROW COL
|
||||
if ! [[ `echo "${ROW#*[}"` == 1 ]];then
|
||||
if [[ $_ps1_verylight ]];then
|
||||
_ps1_Hline=""
|
||||
else
|
||||
if [[ $_ps1_color ]];then
|
||||
_ps1_Hline=`echo;printf "\e[2m🭻\e[0m%.0b" {1..26}`
|
||||
else
|
||||
_ps1_Hline=`echo;printf '🭻%.0b' {1..26}`
|
||||
fi
|
||||
fi
|
||||
printf "%b\n" "${_ps1_Hline}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Preparing infos
|
||||
_ps1__pre_prompt_set() {
|
||||
_ps1_user="$USER"
|
||||
_ps1_host="$HOSTNAME"
|
||||
|
||||
_ps1_file=`\
|
||||
/bin/ls -1Ap \
|
||||
| /bin/grep -v / \
|
||||
| /usr/bin/wc -l \
|
||||
| /bin/sed 's: ::g'`
|
||||
|
||||
_ps1_dirs=`\
|
||||
/bin/ls -1Ap \
|
||||
| /bin/grep / \
|
||||
| /usr/bin/wc -l \
|
||||
| /bin/sed 's: ::g'`
|
||||
|
||||
_ps1_size=`\
|
||||
/bin/ls -lah \
|
||||
| /bin/grep -m 1 total \
|
||||
| /bin/sed 's/total //'`
|
||||
|
||||
_ps1_time=`date +%H:%M`
|
||||
_ps1_hist=$(( `cat $HISTFILE | wc -l` + 1 ))
|
||||
_ps1_h=$PWD
|
||||
|
||||
[[ $_ps1_h/ = "$HOME"/* ]] \
|
||||
&& _ps1_h=\~${_ps1_h#$HOME}
|
||||
|
||||
_ps1__pre_prompt_blankline
|
||||
}
|
||||
|
||||
|
||||
# 1. echolib Colored
|
||||
_ps1__prompt_echolib() {
|
||||
local _ps1_Exit="$?"
|
||||
[[ ${_ps1_Exit} == 0 ]] \
|
||||
&& _ps1_Exit=`echo -e "\e[32m${_ps1_Exit}\e[0m"` \
|
||||
|| _ps1_Exit=`echo -e "\e[31m${_ps1_Exit}\e[0m"`
|
||||
|
||||
_ps1__refresh_history
|
||||
_ps1_color=true
|
||||
_ps1__pre_prompt_set
|
||||
unset _ps1_color
|
||||
|
||||
# Line 1
|
||||
printf "%b %b %b %b\n" \
|
||||
" $_ps1_Exit" \
|
||||
"$_ps1_time" \
|
||||
"${C_Grey}!$_ps1_hist${NC}" \
|
||||
"${C_Green}$_ps1_user${NC}${C_Grey}@${NC}$_ps1_host"
|
||||
# Line 2
|
||||
printf "%b %b %b %b %b\n" \
|
||||
" ${C_Grey}f:${NC}${C_Cyan}$_ps1_file${NC}" \
|
||||
"${C_Grey}D:${NC}${C_Yellow}$_ps1_dirs${NC}" \
|
||||
"${C_Grey}S=${NC}$_ps1_size" \
|
||||
"${C_Grey}>${NC}" \
|
||||
"${C_Yellow}$_ps1_h${NC}"
|
||||
# Line 3
|
||||
PS1='$ '
|
||||
}
|
||||
|
||||
shopt -s histappend
|
||||
export HISTCONTROL=ignoreboth:erasedups
|
||||
PROMPT_COMMAND=_ps1__prompt_echolib
|
||||
export PS1=$PROMPT_COMMAND
|
Loading…
Reference in New Issue