aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2018-02-11 17:37:04 -0500
committerMitch Riedstra <mitch@riedstra.us>2018-02-11 17:37:04 -0500
commit6d105ee1d9f2737493cdb4c5d1317d066a5a5304 (patch)
treef0125df24d29039f0bd3fa26840b03731b9990c4
parent4a208e375dd99a32fd7947c6a11bfefa06f75ea4 (diff)
parent2b12e822f32fd4320600cb999138a16fe3c93d8e (diff)
downloaddotfiles-6d105ee1d9f2737493cdb4c5d1317d066a5a5304.tar.gz
dotfiles-6d105ee1d9f2737493cdb4c5d1317d066a5a5304.tar.xz
Merge branch 'master' of git.riedstra.us:/mitch/dotfiles
-rw-r--r--colors.sh98
-rw-r--r--mkshrc44
2 files changed, 122 insertions, 20 deletions
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
+
diff --git a/mkshrc b/mkshrc
index f2f5fd7..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" ] || \
@@ -38,12 +42,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 +56,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 +67,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 +79,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() {
@@ -103,17 +107,15 @@ 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";
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,7 +129,8 @@ setcoloraliases() {
fi
alias grep="grep --color=auto";
- alias diff='colordiff';
+ 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'
}
@@ -135,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
}
@@ -543,13 +550,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"
@@ -589,11 +593,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
@@ -607,7 +612,6 @@ COLOR=1
set_pager
set_editor
export PATH="$HOME/bin:$PATH"
-export VISUAL="$EDITOR"
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin