diff --git a/.chezmoi.toml.tmpl b/.chezmoi.toml.tmpl index 293bb25..e83ca56 100644 --- a/.chezmoi.toml.tmpl +++ b/.chezmoi.toml.tmpl @@ -5,5 +5,4 @@ name = "{{ $name }}" email = "{{ $email }}" - [bash] - prompt.category = "{{ $category }}" + bash.prompt.category = "{{ $category }}" diff --git a/README.adoc b/README.adoc index 58891a6..05a1d31 100644 --- a/README.adoc +++ b/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`. +.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) TODO: create user file for initialization at provisioning @@ -51,6 +63,14 @@ Alternative way to include .sshrc by detecting SSH connection. [source,bash] ---- # 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 echo "Not a ssh connection" else @@ -58,3 +78,22 @@ else . ~/.sshrc 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 +---- \ No newline at end of file diff --git a/dot_bashrc.d/executable_00.bash.init b/dot_bashrc.d/executable_00.bash.init new file mode 100644 index 0000000..7e7d8e6 --- /dev/null +++ b/dot_bashrc.d/executable_00.bash.init @@ -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 diff --git a/dot_solarize_colors b/dot_bashrc.d/executable_01.solarize_colors similarity index 100% rename from dot_solarize_colors rename to dot_bashrc.d/executable_01.solarize_colors diff --git a/dot_solarize_colors_base b/dot_bashrc.d/executable_01.solarize_colors_base similarity index 100% rename from dot_solarize_colors_base rename to dot_bashrc.d/executable_01.solarize_colors_base diff --git a/dot_bashrc.d/executable_03.ENV b/dot_bashrc.d/executable_03.ENV new file mode 100755 index 0000000..b3ed0d7 --- /dev/null +++ b/dot_bashrc.d/executable_03.ENV @@ -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 diff --git a/dot_bashrc.d/executable_08.alias b/dot_bashrc.d/executable_08.alias new file mode 100644 index 0000000..b52d18b --- /dev/null +++ b/dot_bashrc.d/executable_08.alias @@ -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' diff --git a/dot_bashrc.d/executable_09.functions b/dot_bashrc.d/executable_09.functions new file mode 100755 index 0000000..f4f2b4b --- /dev/null +++ b/dot_bashrc.d/executable_09.functions @@ -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 +} diff --git a/dot_sshrc.tmpl b/dot_bashrc.d/executable_10.sshrc.tmpl similarity index 96% rename from dot_sshrc.tmpl rename to dot_bashrc.d/executable_10.sshrc.tmpl index e3a284b..2daa444 100644 --- a/dot_sshrc.tmpl +++ b/dot_bashrc.d/executable_10.sshrc.tmpl @@ -29,9 +29,7 @@ function lastExitCode { fi } -# sourcing Solarized Theme -# and building PS1 prompt -source $HOME/.solarize_colors_base +# sourcing Solarized Theme is already done in .bashrc.d echo "mySystem: $mySystem" echo "myFQDN: $myFQDN" diff --git a/dot_bashrc.d/executable_bashrc.init b/dot_bashrc.d/executable_bashrc.init new file mode 100644 index 0000000..da4465a --- /dev/null +++ b/dot_bashrc.d/executable_bashrc.init @@ -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 + diff --git a/dot_sshrc b/dot_sshrc deleted file mode 100644 index 59d0633..0000000 --- a/dot_sshrc +++ /dev/null @@ -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="" -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