From 6c9c17409b1c38364dcc5621b6473feb1cf9a5ca Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Mon, 29 Jan 2018 02:33:36 -0500 Subject: A better way of setting the editor --- mkshrc | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/mkshrc b/mkshrc index f2f5fd7..9be5faf 100644 --- a/mkshrc +++ b/mkshrc @@ -543,13 +543,10 @@ colormanpages() { #|_| |_|_|___/\___| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% set_editor() { - export EDITOR="vi" + # export EDITOR="vi" - if [ -x "$(which nvim)" ] ; then - export EDITOR="$(which nvim)" - elif [ -x "$(which vim)" ] ; then - export EDITOR="$(which vim)" - fi + export EDITOR="$(which ed mg nano vi vim nvim 2>/dev/null | tail -n1)" + export VISUAL="$EDITOR" # Set an alias for our editor of choice alias vi="$EDITOR" @@ -607,7 +604,6 @@ COLOR=1 set_pager set_editor export PATH="$HOME/bin:$PATH" -export VISUAL="$EDITOR" export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin -- cgit v1.2.3 From 5880ffbce8b3b2e2d6b4bf2e2600527280d3199d Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Sat, 3 Feb 2018 15:26:20 -0500 Subject: Fall back to regular diff if colordiff isn't available. Default to -F on ls aliases --- mkshrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mkshrc b/mkshrc index 9be5faf..a9a6c0d 100644 --- a/mkshrc +++ b/mkshrc @@ -103,8 +103,8 @@ fi #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% setaliases() { alias ls="ls -F"; - alias l="ls -lh"; - alias ll="ls -l"; + alias l="ls -lhF"; + alias ll="ls -lhF"; alias g="grep"; alias m="$PAGER"; alias j="jobs"; @@ -127,7 +127,7 @@ setcoloraliases() { fi alias grep="grep --color=auto"; - alias diff='colordiff'; + alias diff="$(which diff colordiff 2>/dev/null | tail -n 1)"; alias search='egrep --color=auto -rnI'; alias t='tree -CdL' } -- cgit v1.2.3 From 57ef6eed56a626fd5ff386dce6f71a8ede291e50 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Sat, 3 Feb 2018 23:42:57 -0500 Subject: Remove egrep from color aliases --- mkshrc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mkshrc b/mkshrc index a9a6c0d..21f45f2 100644 --- a/mkshrc +++ b/mkshrc @@ -111,9 +111,7 @@ setaliases() { alias p="pwd"; alias gdb='gdb -q' alias bc='bc -q' - alias egrep='egrep --color=auto' alias eg='egrep' - alias egf='egrep --color=force' alias search='egrep -rniI' } @@ -127,6 +125,7 @@ setcoloraliases() { fi alias grep="grep --color=auto"; + alias egrep='egrep --color=auto' alias diff="$(which diff colordiff 2>/dev/null | tail -n 1)"; alias search='egrep --color=auto -rnI'; alias t='tree -CdL' @@ -586,11 +585,12 @@ export LANG="$1"; NEWLINE='$(printf "\n")' SHELL_CONFIG=".mkshrc" -PRELOAD="$HOME/${SHELL_CONFIG}.pre" -LOCAL="$HOME/${SHELL_CONFIG}.local" -UPDATE_URL="https://www.rygel.us/etc/" FANCY_PROMPT=1 COLOR=1 +UPDATE_URL="https://www.rygel.us/etc/" + +PRELOAD="$HOME/${SHELL_CONFIG}.pre" +LOCAL="$HOME/${SHELL_CONFIG}.local" # For use with SSL functions # Just use easy-rsa, it's less hassle -- cgit v1.2.3 From 156297140380bf4b46d8058e7e6df0b56637fda4 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Wed, 7 Feb 2018 21:13:12 -0500 Subject: Remove -s from hostname do to incompatibilities with GNU hostname on Void Linux --- mkshrc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mkshrc b/mkshrc index 21f45f2..64012fe 100644 --- a/mkshrc +++ b/mkshrc @@ -38,12 +38,12 @@ precmd() { (( e )) && print -n "$e|" } set_ps1() { - PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${USER_C}${USER:=$(id -un)}@$(hostname -s)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C} + PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${USER_C}${USER:=$(id -un)}@$(hostname)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C} ${END_P} ' export PS1; } set_root_ps1() { -PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${HOST_C}$(hostname -s)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C} +PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${HOST_C}$(hostname)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C} ${END_P} ' export PS1; } @@ -52,7 +52,7 @@ set_prompt() { if [ `id -u` -eq 0 ] ; then # Previously # Red for root, and no username - # PS1="$(hostname -s) \$PWD + # PS1="$(hostname) \$PWD BG="" ACCENT_C="" ACCENT_P="|" @@ -63,7 +63,7 @@ set_prompt() { set_root_ps1 else # Previously - # PS1="${USER:=$(id -un)}@$(hostname -s) \$PWD + # PS1="${USER:=$(id -un)}@$(hostname) \$PWD BG="" ACCENT_C="" ACCENT_P="|" @@ -75,7 +75,7 @@ set_prompt() { fi } set_basic_prompt() { - PS1="$(precmd)${USER:=$(id -un)}@$(hostname -s) \$PWD $ " + PS1="$(precmd)${USER:=$(id -un)}@$(hostname) \$PWD $ " export PS1; } set_super_basic_prompt() { -- cgit v1.2.3 From 1b90b7a843b46f6a3e2f695804e351d7ded44848 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Thu, 8 Feb 2018 20:22:02 -0500 Subject: Add in xbps aliases as well as a way to include the mkshrc in the global profile --- mkshrc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mkshrc b/mkshrc index 64012fe..af09ae7 100644 --- a/mkshrc +++ b/mkshrc @@ -8,6 +8,10 @@ # # Personally I use this with mksh, .mkshrc is auto loaded by mksh +# Nifty little line that will force the script to return if it's not runnking KSH +# Automatically uncommented if installed system-wide with "install_mkshrc_system" +# [ -z "$KSH_VERSION" ] && return + # This will hopefully fix the bullshit with zsh if \ [ $SHELL = "/bin/zsh" ] || \ @@ -134,16 +138,20 @@ setcoloraliases() { setsudoaliases() { if which sudo > /dev/null 2>&1 && [ -x "$(which sudo)" ] ; then # Package managers + # Isn't it amazing how many distros you end up using? alias apt-get='sudo apt-get' alias yum='sudo dnf' alias dnf='sudo dnf' alias pacman='sudo pacman' + alias xbps-install='sudo xbps-install' + alias xbps-remove='sudo xbps-remove' alias pkg='sudo pkg' # Filesystem utilities alias zfs='sudo zfs' alias btrfs='sudo btrfs' alias mount='sudo mount' + alias umount='sudo umount' fi } -- cgit v1.2.3 From 2b12e822f32fd4320600cb999138a16fe3c93d8e Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Fri, 9 Feb 2018 22:40:37 -0500 Subject: Added a script to print terminal colors --- colors.sh | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 colors.sh diff --git a/colors.sh b/colors.sh new file mode 100644 index 0000000..e5322e1 --- /dev/null +++ b/colors.sh @@ -0,0 +1,98 @@ +#!/bin/bash +#https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/e50a28ec54188d2413518788de6c6367ffcea4f7/print256colours.sh + +# Tom Hale, 2016. MIT Licence. +# Print out 256 colours, with each number printed in its corresponding colour +# See http://askubuntu.com/questions/821157/print-a-256-color-test-pattern-in-the-terminal/821163#821163 + +set -eu # Fail on errors or undeclared variables + +printable_colours=256 + +# Return a colour that contrasts with the given colour +# Bash only does integer division, so keep it integral +function contrast_colour { + local r g b luminance + colour="$1" + + if (( colour < 16 )); then # Initial 16 ANSI colours + (( colour == 0 )) && printf "15" || printf "0" + return + fi + + # Greyscale # rgb_R = rgb_G = rgb_B = (number - 232) * 10 + 8 + if (( colour > 231 )); then # Greyscale ramp + (( colour < 244 )) && printf "15" || printf "0" + return + fi + + # All other colours: + # 6x6x6 colour cube = 16 + 36*R + 6*G + B # Where RGB are [0..5] + # See http://stackoverflow.com/a/27165165/5353461 + + # r=$(( (colour-16) / 36 )) + g=$(( ((colour-16) % 36) / 6 )) + # b=$(( (colour-16) % 6 )) + + # If luminance is bright, print number in black, white otherwise. + # Green contributes 587/1000 to human perceived luminance - ITU R-REC-BT.601 + (( g > 2)) && printf "0" || printf "15" + return + + # Uncomment the below for more precise luminance calculations + + # # Calculate percieved brightness + # # See https://www.w3.org/TR/AERT#color-contrast + # # and http://www.itu.int/rec/R-REC-BT.601 + # # Luminance is in range 0..5000 as each value is 0..5 + # luminance=$(( (r * 299) + (g * 587) + (b * 114) )) + # (( $luminance > 2500 )) && printf "0" || printf "15" +} + +# Print a coloured block with the number of that colour +function print_colour { + local colour="$1" contrast + contrast=$(contrast_colour "$1") + printf "\e[48;5;%sm" "$colour" # Start block of colour + printf "\e[38;5;%sm%3d" "$contrast" "$colour" # In contrast, print number + printf "\e[0m " # Reset colour +} + +# Starting at $1, print a run of $2 colours +function print_run { + local i + for (( i = "$1"; i < "$1" + "$2" && i < printable_colours; i++ )) do + print_colour "$i" + done + printf " " +} + +# Print blocks of colours +function print_blocks { + local start="$1" i + local end="$2" # inclusive + local block_cols="$3" + local block_rows="$4" + local blocks_per_line="$5" + local block_length=$((block_cols * block_rows)) + + # Print sets of blocks + for (( i = start; i <= end; i += (blocks_per_line-1) * block_length )) do + printf "\n" # Space before each set of blocks + # For each block row + for (( row = 0; row < block_rows; row++ )) do + # Print block columns for all blocks on the line + for (( block = 0; block < blocks_per_line; block++ )) do + print_run $(( i + (block * block_length) )) "$block_cols" + done + (( i += block_cols )) # Prepare to print the next row + printf "\n" + done + done +} + +print_run 0 16 # The first 16 colours are spread over the whole spectrum +printf "\n" +print_blocks 16 231 6 6 3 # 6x6x6 colour cube between 16 and 231 inclusive +print_blocks 232 255 12 2 1 # Not 50, but 24 Shades of Grey + -- cgit v1.2.3