Merge branch 'bashrc.d'
This commit is contained in:
commit
599827a361
@ -5,5 +5,4 @@
|
|||||||
name = "{{ $name }}"
|
name = "{{ $name }}"
|
||||||
email = "{{ $email }}"
|
email = "{{ $email }}"
|
||||||
|
|
||||||
[bash]
|
bash.prompt.category = "{{ $category }}"
|
||||||
prompt.category = "{{ $category }}"
|
|
||||||
|
|||||||
39
README.adoc
39
README.adoc
@ -16,6 +16,18 @@ Test with `centos7-01`:
|
|||||||
|
|
||||||
After that a `bin` directory will exist (if not yet present before), move the executable to this dir to have it `PATH`.
|
After that a `bin` directory will exist (if not yet present before), move the executable to this dir to have it `PATH`.
|
||||||
|
|
||||||
|
.add to .bashrc
|
||||||
|
[source,bash]
|
||||||
|
----
|
||||||
|
# If not running interactively, don't do anything
|
||||||
|
# see https://stackoverflow.com/questions/12440287/scp-doesnt-work-when-echo-in-bashrc
|
||||||
|
[[ "$-" != *i* ]] && return
|
||||||
|
|
||||||
|
if [ -x ~/.bashrc.d/bashrc.init ]; then
|
||||||
|
. ~/.bashrc.d/bashrc.init
|
||||||
|
fi
|
||||||
|
----
|
||||||
|
|
||||||
=== AWS Systeme (Draft)
|
=== AWS Systeme (Draft)
|
||||||
|
|
||||||
TODO: create user file for initialization at provisioning
|
TODO: create user file for initialization at provisioning
|
||||||
@ -51,6 +63,14 @@ Alternative way to include .sshrc by detecting SSH connection.
|
|||||||
[source,bash]
|
[source,bash]
|
||||||
----
|
----
|
||||||
# User specific aliases and functions
|
# User specific aliases and functions
|
||||||
|
|
||||||
|
# test if the prompt var is not set
|
||||||
|
# See https://unix.stackexchange.com/questions/154395/running-scp-when-bashrc-of-remote-machine-includes-source-command
|
||||||
|
if [ -z "$PS1" ]; then
|
||||||
|
# prompt var is not set, so this is *not* an interactive shell
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -f ~/.sshrc ] && [ -z "$SSH_CLIENT" ]; then
|
if [ -f ~/.sshrc ] && [ -z "$SSH_CLIENT" ]; then
|
||||||
echo "Not a ssh connection"
|
echo "Not a ssh connection"
|
||||||
else
|
else
|
||||||
@ -58,3 +78,22 @@ else
|
|||||||
. ~/.sshrc
|
. ~/.sshrc
|
||||||
fi
|
fi
|
||||||
----
|
----
|
||||||
|
|
||||||
|
=== cygwin
|
||||||
|
|
||||||
|
When using cygwin, the `chezmoi` executable has defaults for Windows.
|
||||||
|
That means the default HOME dir is the Windows `%USERPROFILE%` directory.
|
||||||
|
To provide the managed files to the cygwin path `/home/user` the target directory has to be adjusted while calling `chezmoi`.
|
||||||
|
|
||||||
|
[source,console]
|
||||||
|
----
|
||||||
|
H:\>chezmoi apply -D C:\cygwin64\home\user
|
||||||
|
|
||||||
|
H:\>chezmoi -D C:\cygwin64\home\user managed
|
||||||
|
C:\cygwin64\home\user\.gitconfig
|
||||||
|
C:\cygwin64\home\user\.solarize_colors
|
||||||
|
C:\cygwin64\home\user\.solarize_colors_base
|
||||||
|
C:\cygwin64\home\user\.sshrc
|
||||||
|
C:\cygwin64\home\user\.vimrc
|
||||||
|
C:\cygwin64\home\user\bin
|
||||||
|
----
|
||||||
10
dot_bashrc.d/executable_00.bash.init
Normal file
10
dot_bashrc.d/executable_00.bash.init
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Bash Options
|
||||||
|
HISTCONTROL=ignoredups:ignorespace
|
||||||
|
HISTSIZE=3000
|
||||||
|
HISTFILESIZE=3000
|
||||||
|
export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
|
||||||
|
export HISTIGNORE=$'[ \t]*:&:[fb]g:exit:ls:ll:cd:pwd:history:z'
|
||||||
|
|
||||||
|
# inspired (but not all commands used) by https://github.com/jdcapa/bashrc.d/blob/main/00.bash.init
|
||||||
22
dot_bashrc.d/executable_03.ENV
Executable file
22
dot_bashrc.d/executable_03.ENV
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# BINs and PATH
|
||||||
|
# extend path if directory exists and is not yet contained
|
||||||
|
# https://askubuntu.com/questions/432217/prevent-duplicate-entries-in-path
|
||||||
|
function extendPath() {
|
||||||
|
local new_dir=$1
|
||||||
|
if [ -d "$new_dir" ]; then
|
||||||
|
[[ ":$PATH:" =~ :$new_dir: ]] || PATH="$new_dir:$PATH"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -x /usr/bin/go ]; then
|
||||||
|
extendPath "$(go env GOPATH)/bin"
|
||||||
|
export GOPATH=$(go env GOPATH)
|
||||||
|
fi
|
||||||
|
|
||||||
|
extendPath "$HOME/bin"
|
||||||
|
extendPath "/usr/local/bin"
|
||||||
|
extendPath "$HOME/.local/bin"
|
||||||
|
|
||||||
|
export PATH
|
||||||
30
dot_bashrc.d/executable_08.alias
Normal file
30
dot_bashrc.d/executable_08.alias
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# navigation
|
||||||
|
alias ..='cd ..'
|
||||||
|
alias ...='cd ../..'
|
||||||
|
alias ....='cd ../../..'
|
||||||
|
|
||||||
|
# ls aliases
|
||||||
|
alias ll='ls -l --group-directories-first'
|
||||||
|
alias ls='ls -hF --color' # add colors for filetype recognition
|
||||||
|
alias lo='ls -o' # without group information
|
||||||
|
alias lr='ls -lrt'
|
||||||
|
alias la='ls -Al' # show hidden files
|
||||||
|
alias lx='ls -lXB' # sort by extension
|
||||||
|
alias lk='ls -lSr' # sort by size, biggest last
|
||||||
|
alias lc='ls -ltcr' # sort by and show change time, most recent last
|
||||||
|
alias lu='ls -ltur' # sort by and show access time, most recent last
|
||||||
|
alias lt='ls -ltr' # sort by date, most recent last
|
||||||
|
alias lm='ls -al |more' # pipe through 'more'
|
||||||
|
alias l='ls -CF'
|
||||||
|
alias lsd='ls -l | grep "^d"' #list only directories
|
||||||
|
|
||||||
|
# git shortcut
|
||||||
|
alias gg='git graph'
|
||||||
|
|
||||||
|
# tail alias
|
||||||
|
alias tailer="tail --follow=name --retry"
|
||||||
|
|
||||||
|
# git aliases
|
||||||
|
alias gg='git graph'
|
||||||
13
dot_bashrc.d/executable_09.functions
Executable file
13
dot_bashrc.d/executable_09.functions
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Bash Functions sourced by .bashrc / .sshrc
|
||||||
|
#
|
||||||
|
|
||||||
|
# Get SSL Certificate information
|
||||||
|
# Based on https://serverfault.com/questions/661978/displaying-a-remote-ssl-certificate-details-using-cli-tools
|
||||||
|
function getCertInfo() {
|
||||||
|
local myServer=${1:?a Servername is required}
|
||||||
|
local myPort=${2:-443}
|
||||||
|
|
||||||
|
echo | openssl s_client -showcerts -servername $myServer -connect $myServer:$myPort 2>/dev/null | openssl x509 -inform pem -noout -text
|
||||||
|
}
|
||||||
@ -29,9 +29,7 @@ function lastExitCode {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# sourcing Solarized Theme
|
# sourcing Solarized Theme is already done in .bashrc.d
|
||||||
# and building PS1 prompt
|
|
||||||
source $HOME/.solarize_colors_base
|
|
||||||
echo "mySystem: $mySystem"
|
echo "mySystem: $mySystem"
|
||||||
echo "myFQDN: $myFQDN"
|
echo "myFQDN: $myFQDN"
|
||||||
|
|
||||||
11
dot_bashrc.d/executable_bashrc.init
Normal file
11
dot_bashrc.d/executable_bashrc.init
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# This churns through files in $HOME/.bashrc.d if they are executable.
|
||||||
|
if [ -d $HOME/.bashrc.d ]; then
|
||||||
|
for x in $HOME/.bashrc.d/* ; do
|
||||||
|
if [[ "${x##*/}" != "bashrc.init" ]]; then
|
||||||
|
test -f "$x" || continue
|
||||||
|
test -x "$x" || continue
|
||||||
|
. "$x"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
114
dot_sshrc
114
dot_sshrc
@ -1,114 +0,0 @@
|
|||||||
#
|
|
||||||
# sshrc will be called byaliased ssh command 's'.
|
|
||||||
#
|
|
||||||
# if [ -f $HOME/.profile ]; then
|
|
||||||
# source $HOME/.profile
|
|
||||||
# fi
|
|
||||||
# if [ -f $HOME/.bashrc ]; then
|
|
||||||
# source $HOME/.bashrc
|
|
||||||
# fi
|
|
||||||
|
|
||||||
#
|
|
||||||
# System Name and type detectedn
|
|
||||||
#
|
|
||||||
mySystem=$(uname -n)
|
|
||||||
myFQDN="$(uname -n).$(dnsdomainname)"
|
|
||||||
if [ -f /etc/os-release ];then
|
|
||||||
myPrettyName=$(grep PRETTY_NAME /etc/os-release)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# last exit code
|
|
||||||
function lastExitCode {
|
|
||||||
local exit="$?"
|
|
||||||
|
|
||||||
if [ $exit != 0 ];then
|
|
||||||
printf '\e[38;5;160m%-5s' "✕ ❗ ($exit)"
|
|
||||||
else
|
|
||||||
printf '✔'
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# sourcing Solarized Theme
|
|
||||||
# and building PS1 prompt
|
|
||||||
source $HOME/.solarize_colors_base
|
|
||||||
echo "mySystem: $mySystem"
|
|
||||||
echo "myFQDN: $myFQDN"
|
|
||||||
|
|
||||||
bg_reset="\[\e[49m\]"
|
|
||||||
fg_reset="\[\e[39m\]"
|
|
||||||
|
|
||||||
SYSTEM="<TODO>"
|
|
||||||
bg_system="${sol_bg_magenta}"
|
|
||||||
fg_system="${sol_magenta}"
|
|
||||||
fg_type="${sol_magenta}"
|
|
||||||
|
|
||||||
bg_type="${sol_bg_base3}"
|
|
||||||
fg_arrow1="${fg_type}"
|
|
||||||
fg_arrow2="${sol_base3}"
|
|
||||||
|
|
||||||
if [[ -z "${myType// }" ]]; then
|
|
||||||
TYPE=$(uname -n)
|
|
||||||
else
|
|
||||||
TYPE=" $myType "
|
|
||||||
fi
|
|
||||||
if [ "$myNum" != "0" ]; then
|
|
||||||
TYPE="$TYPE ($myNum)"
|
|
||||||
fi
|
|
||||||
echo "System Prompt: $SYSTEM_PROMPT"
|
|
||||||
|
|
||||||
SYSTEM_PROMPT="\n${fg_arrow1}░▒▓${bg_system} ${fg_sytem}${SYSTEM} ${bg_type}${fg_arrow1}▓▒░"
|
|
||||||
TYPE_PROMPT="$TYPE \$(lastExitCode) ${fg_arrow1} $mySlesVersion ${sol_blue}\${STY#[0-9]*.} ${bg_reset}${fg_arrow2}▓▒░"
|
|
||||||
|
|
||||||
PROMPT="${SYSTEM_PROMPT} ${TYPE_PROMPT}"
|
|
||||||
DATE="\[\e[0;32m\]\d \t"
|
|
||||||
if [ "$(whoami)" = "root" ]; then
|
|
||||||
DIR="\[\e[97;49m\]\[\e[0;91;107m\] \u@\h \[\e[97;49m\]\[\e[39;49m\] in \[\e[0;32m\]\w"
|
|
||||||
else
|
|
||||||
DIR="\[\e[0;32m\]\u@\h \[\e[31m\]☆ \[\e[0;32m\]\w"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# PROMPT_COMMAND=promptcmd
|
|
||||||
|
|
||||||
PS1="${PROMPT}\[\e[0m\] \n${DIR}\n${DATE} → \[\e[0m\]"
|
|
||||||
|
|
||||||
if [ $(whoami | grep root | wc -l) == 1 ]; then
|
|
||||||
echo -e "\e[31;107m┌─────────────────────────────┐\e[0m"
|
|
||||||
echo -e "\e[31;107m│ YOU ARE ROOT, BE CAREFUL! │\e[0m"
|
|
||||||
echo -e "\e[31;107m└─────────────────────────────┘\e[0m"
|
|
||||||
|
|
||||||
# Test mintty
|
|
||||||
echo -ne '\e]11;44,10,10\a'
|
|
||||||
fi
|
|
||||||
|
|
||||||
# TODO: background colors...
|
|
||||||
# TODO: private history file for shared accounts
|
|
||||||
# TODO: vim
|
|
||||||
|
|
||||||
export LS_OPTIONS='--color=auto'
|
|
||||||
eval "$(dircolors -b)"
|
|
||||||
alias ls='ls $LS_OPTIONS'
|
|
||||||
|
|
||||||
alias psg='ps -aux | grep -v grep | grep '
|
|
||||||
|
|
||||||
# Some functions (some by c't magazine)
|
|
||||||
cdl() {
|
|
||||||
cd "$@"
|
|
||||||
if [ "$?" == 0 ]; then
|
|
||||||
ls
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
backup() {
|
|
||||||
cp -p "$@" "$@".backup-$(date +%Y-%m-%d_%H_%M_%S)
|
|
||||||
}
|
|
||||||
|
|
||||||
extract() {
|
|
||||||
case $1 in
|
|
||||||
*.tar.bz2) tar xvjf $1;;
|
|
||||||
*.tar.gz|*.tgz) tar xvfz $1;;
|
|
||||||
*.zip) unzip $1;;
|
|
||||||
*) echo "Not supported: $1";;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
PATH=$PATH:$HOME/bin
|
|
||||||
Loading…
Reference in New Issue
Block a user