Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- ansible
- Elasticsearch
- docker
- Kibana
- PlayBook
- hardening
- GitLab
- proxycfg
- Proxy
- bash
- XCP-ng
- x-pack
- Windows
- freebsd
- macos
- xe guest utilities
- pfsense
- 한글가이드
- 로그인불가
- miniconda
- G-suite
- Kibana server is not ready yet
- centos 8
- ELASTIC
- application security
- elastic stack
- 보안양파
- endpoint security
- ssh key 배포
Archives
- Today
- Total
선 밖에 선 자유인
bash prompt 설정 본문
https://martin.ankerl.com/2016/11/04/linux-bash-prompt/
Linux Bash Prompt
Elapsed time, errorcode ✘ or ✔, git & svn status, ...
martin.ankerl.com
function prompt_timer_start {
PROMPT_TIMER=${PROMPT_TIMER:-`date +%s.%3N`}
echo -ne "\033]0;${@}\007"
}
function prompt_svn_stats() {
command -v svn >/dev/null
if [ $? != 0 ]; then
return
fi
local WCROOT=`svn info --show-item wc-root 2>/dev/null`
if [ -z "$WCROOT" ]; then
return
fi
local SVN_INFO=`svn info ${WCROOT} 2>/dev/null`
local CHECKEDOUTURL=`echo "${SVN_INFO}" |sed -ne 's#^URL: ##p'`
local REV=`echo "${SVN_INFO}" |sed -ne 's#^Revision: ##p'`
local ROOTURL=`echo "${SVN_INFO}" |sed -ne 's#^Repository Root: ##p'`
echo " (\e[32m${CHECKEDOUTURL/$ROOTURL\//}\e[1;30m@\e[0;100m${REV})"
}
function prompt_timer_stop {
local EXIT="$?" # MUST come first
local NOW=`date +%s.%3N` # should be high up, for accurate measurement
echo -ne "\033]0;$USER@$HOSTNAME: $PWD\007"
local ELAPSED=$(bc <<< "$NOW - $PROMPT_TIMER")
unset PROMPT_TIMER
local T=${ELAPSED%.*}
local AFTER_COMMA=${ELAPSED##*.}
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
local TIMER_SHOW=
[[ $D > 0 ]] && TIMER_SHOW=${TIMER_SHOW}$(printf '%dd ' $D)
[[ $H > 0 ]] && TIMER_SHOW=${TIMER_SHOW}$(printf '%dh ' $H)
[[ $M > 0 ]] && TIMER_SHOW=${TIMER_SHOW}$(printf '%dm ' $M)
TIMER_SHOW=${TIMER_SHOW}$(printf "%d.${AFTER_COMMA}s" $S)
PS1="\e[0m\n" # begin with a newline
if [ $EXIT != 0 ]; then
PS1+="\e[1;41m ✘ ${EXIT}" # red x with error status
else
PS1+="\e[1;42m ✔" # green tick
fi
PS1+=" \e[0;100;93m `date +%H:%M`" # date, e.g. 17:00
#local PSCHAR="┕▶"
local PSCHAR="▶"
if [ $(id -u) -eq 0 ]; then
PS1+=" \e[1;31m\h " # root: red hostname
PSCHAR="\e[1;31m#\e[0m"
else
PS1+=" \e[1;32m\h " # non-root: green hostname
fi
PS1+="\e[1;94m\w" # working directory
GIT_PS1_SHOWDIRTYSTATE=true # * unstaged, + staged
GIT_PS1_SHOWSTASHSTATE=true # $ stashed
GIT_PS1_SHOWUNTRACKEDFILES=true # % untracked
GIT_PS1_SHOWCOLORHINTS=true
# < behind, > ahead, <> diverged, = same as upstream
GIT_PS1_SHOWUPSTREAM="auto"
# git with 2 arguments *sets* PS1 (and uses color coding)
__git_ps1 "${PS1}\e[0;100m" "\e[0;100m"
# try to append svn
PS1+=`prompt_svn_stats`
PS1+=" \e[0;100;93m${TIMER_SHOW}" # runtime of last command
PS1+=" \e[0m\n${PSCHAR} " # prompt in new line
#PS1+="\e[K\e[0m\n${PSCHAR} " # prompt in new line
}
# see https://gnunn1.github.io/tilix-web/manual/vteconfig/
if [ $TILIX_ID ] || [ $VTE_VERSION ]; then
source /etc/profile.d/vte.sh
fi
trap 'prompt_timer_start "$BASH_COMMAND (`date +%H:%M:%S`)"' DEBUG
PROMPT_COMMAND=prompt_timer_stop
Comments