From f6d61543a21954d6ca668c65ed71cfc617cc7349 Mon Sep 17 00:00:00 2001 From: Stefan Gaiselmann Date: Mon, 9 Nov 2020 16:48:28 +0100 Subject: [PATCH 01/12] Added check for interactive shell to README. --- README.adoc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.adoc b/README.adoc index 58891a6..4d17b83 100644 --- a/README.adoc +++ b/README.adoc @@ -51,6 +51,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 From 0ff613926e1fe6d81a2dc624c51e33f4d8e6e212 Mon Sep 17 00:00:00 2001 From: Stefan Gaiselmann Date: Tue, 10 Nov 2020 15:56:21 +0100 Subject: [PATCH 02/12] Added .bashrc.d directory with initial alias and function for testing. --- dot_bashrc.d/08.alias | 10 ++++++++++ dot_bashrc.d/09.functions | 13 +++++++++++++ dot_bashrc.d/bashrc.init | 11 +++++++++++ 3 files changed, 34 insertions(+) create mode 100755 dot_bashrc.d/08.alias create mode 100755 dot_bashrc.d/09.functions create mode 100644 dot_bashrc.d/bashrc.init diff --git a/dot_bashrc.d/08.alias b/dot_bashrc.d/08.alias new file mode 100755 index 0000000..87a3b2a --- /dev/null +++ b/dot_bashrc.d/08.alias @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# navigation +alias +='pushd .' +alias -='popd' +alias ..='cd ..' +alias ...='cd ../..' + +# tail alias +alias tailer="tail --follow=name --retry" diff --git a/dot_bashrc.d/09.functions b/dot_bashrc.d/09.functions new file mode 100755 index 0000000..f4f2b4b --- /dev/null +++ b/dot_bashrc.d/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_bashrc.d/bashrc.init b/dot_bashrc.d/bashrc.init new file mode 100644 index 0000000..da4465a --- /dev/null +++ b/dot_bashrc.d/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 + From f964f2f060a06a63fc17de99a7c5279b2c8dca94 Mon Sep 17 00:00:00 2001 From: "FCD (ubersapce)" Date: Tue, 10 Nov 2020 16:08:09 +0100 Subject: [PATCH 03/12] Made basrc.d files executable. --- dot_bashrc.d/{08.alias => executable_08.alias} | 0 dot_bashrc.d/{09.functions => executable_09.functions} | 0 dot_bashrc.d/{bashrc.init => executable_bashrc.init} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename dot_bashrc.d/{08.alias => executable_08.alias} (100%) mode change 100755 => 100644 rename dot_bashrc.d/{09.functions => executable_09.functions} (100%) rename dot_bashrc.d/{bashrc.init => executable_bashrc.init} (100%) diff --git a/dot_bashrc.d/08.alias b/dot_bashrc.d/executable_08.alias old mode 100755 new mode 100644 similarity index 100% rename from dot_bashrc.d/08.alias rename to dot_bashrc.d/executable_08.alias diff --git a/dot_bashrc.d/09.functions b/dot_bashrc.d/executable_09.functions similarity index 100% rename from dot_bashrc.d/09.functions rename to dot_bashrc.d/executable_09.functions diff --git a/dot_bashrc.d/bashrc.init b/dot_bashrc.d/executable_bashrc.init similarity index 100% rename from dot_bashrc.d/bashrc.init rename to dot_bashrc.d/executable_bashrc.init From 84b71f01a267dda81b5c029750ce42e5e24741b2 Mon Sep 17 00:00:00 2001 From: "FCD (ubersapce)" Date: Tue, 10 Nov 2020 16:13:01 +0100 Subject: [PATCH 04/12] Moved .sshrc to .bashrc.d directory. --- dot_sshrc => dot_bashrc.d/10.sshrc | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dot_sshrc => dot_bashrc.d/10.sshrc (100%) diff --git a/dot_sshrc b/dot_bashrc.d/10.sshrc similarity index 100% rename from dot_sshrc rename to dot_bashrc.d/10.sshrc From 004b683ec33cf26aca2dc0845cea2c44807ac913 Mon Sep 17 00:00:00 2001 From: "FCD (ubersapce)" Date: Tue, 10 Nov 2020 16:13:54 +0100 Subject: [PATCH 05/12] Removed pushd, popd (raised errors on uberspace). --- dot_bashrc.d/executable_08.alias | 2 -- 1 file changed, 2 deletions(-) diff --git a/dot_bashrc.d/executable_08.alias b/dot_bashrc.d/executable_08.alias index 87a3b2a..129bbfe 100644 --- a/dot_bashrc.d/executable_08.alias +++ b/dot_bashrc.d/executable_08.alias @@ -1,8 +1,6 @@ #!/usr/bin/env bash # navigation -alias +='pushd .' -alias -='popd' alias ..='cd ..' alias ...='cd ../..' From 22776b8bddb8f7c724fc874fe7a6d81d88bbe6dc Mon Sep 17 00:00:00 2001 From: "FCD (ubersapce)" Date: Tue, 10 Nov 2020 16:15:34 +0100 Subject: [PATCH 06/12] Fixed wrong internal name for .sshrc. --- dot_bashrc.d/{10.sshrc => executable_10.sshrc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dot_bashrc.d/{10.sshrc => executable_10.sshrc} (100%) diff --git a/dot_bashrc.d/10.sshrc b/dot_bashrc.d/executable_10.sshrc similarity index 100% rename from dot_bashrc.d/10.sshrc rename to dot_bashrc.d/executable_10.sshrc From f147a16052241f10250930aac8259412f7ea795c Mon Sep 17 00:00:00 2001 From: Stefan Gaiselmann Date: Wed, 11 Nov 2020 10:32:46 +0100 Subject: [PATCH 07/12] =?UTF-8?q?=E2=80=9EREADME.adoc=E2=80=9C=20=C3=A4nde?= =?UTF-8?q?rn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.adoc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.adoc b/README.adoc index 4d17b83..40f317b 100644 --- a/README.adoc +++ b/README.adoc @@ -66,3 +66,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 From 2d60f939ab17ba1635c8f2fec592db35ff1f73b1 Mon Sep 17 00:00:00 2001 From: "FCD (uberspace)" Date: Wed, 11 Nov 2020 11:15:20 +0100 Subject: [PATCH 08/12] Adjusted solarize color integration (bashrc.d). --- .../executable_01.solarize_colors | 0 .../executable_01.solarize_colors_base | 0 dot_bashrc.d/executable_10.sshrc | 114 ------------------ .../executable_10.sshrc.tmpl | 4 +- 4 files changed, 1 insertion(+), 117 deletions(-) rename dot_solarize_colors => dot_bashrc.d/executable_01.solarize_colors (100%) rename dot_solarize_colors_base => dot_bashrc.d/executable_01.solarize_colors_base (100%) delete mode 100644 dot_bashrc.d/executable_10.sshrc rename dot_sshrc.tmpl => dot_bashrc.d/executable_10.sshrc.tmpl (96%) 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_10.sshrc b/dot_bashrc.d/executable_10.sshrc deleted file mode 100644 index 59d0633..0000000 --- a/dot_bashrc.d/executable_10.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 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" From 0e7665b31967cf1818a1119646c5b02096324d6d Mon Sep 17 00:00:00 2001 From: "FCD (uberspace)" Date: Wed, 11 Nov 2020 11:18:09 +0100 Subject: [PATCH 09/12] Added git alias 'gg' (git graph). --- dot_bashrc.d/executable_08.alias | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dot_bashrc.d/executable_08.alias b/dot_bashrc.d/executable_08.alias index 129bbfe..1948577 100644 --- a/dot_bashrc.d/executable_08.alias +++ b/dot_bashrc.d/executable_08.alias @@ -6,3 +6,6 @@ alias ...='cd ../..' # tail alias alias tailer="tail --follow=name --retry" + +# git aliases +alias gg='git graph' From ba2ba061adf7748936a19cec178133c77be7419a Mon Sep 17 00:00:00 2001 From: Stefan Gaiselmann Date: Thu, 12 Nov 2020 19:46:52 +0100 Subject: [PATCH 10/12] =?UTF-8?q?=E2=80=9EREADME.adoc=E2=80=9C=20=C3=A4nde?= =?UTF-8?q?rn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.adoc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.adoc b/README.adoc index 40f317b..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 From 7a99efad195ea476b0bb6b1e209f7fb3ed093580 Mon Sep 17 00:00:00 2001 From: Stefan Gaiselmann Date: Fri, 13 Nov 2020 08:01:45 +0100 Subject: [PATCH 11/12] Extended .bashrc.d configuration. --- dot_bashrc.d/executable_00.bash.init | 10 ++++++++++ dot_bashrc.d/executable_03.ENV | 22 ++++++++++++++++++++++ dot_bashrc.d/executable_08.alias | 19 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 dot_bashrc.d/executable_00.bash.init create mode 100755 dot_bashrc.d/executable_03.ENV 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_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 index 1948577..b52d18b 100644 --- a/dot_bashrc.d/executable_08.alias +++ b/dot_bashrc.d/executable_08.alias @@ -3,6 +3,25 @@ # 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" From 15570330494497a5cc5f0a33f94fe28688229fb2 Mon Sep 17 00:00:00 2001 From: Stefan Gaiselmann Date: Fri, 13 Nov 2020 08:03:56 +0100 Subject: [PATCH 12/12] Changed configuration template (correction for bash.prompt.category). --- .chezmoi.toml.tmpl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 }}"