Removing unneeded pages, updating bashrc documentation

This commit is contained in:
David Thurstenson 2019-05-17 18:25:20 -05:00
parent f5b370f2f3
commit 0983ada81d
4 changed files with 163 additions and 110 deletions

View File

@ -2,48 +2,6 @@
Source: https://git.thurstylark.com/vcsh/bashrc.git
----
==Prompt==
I originally built my prompt using http://bashrcgenerator.com and, while it's a nice tool for visually building a prompt, it has several limitations on what you're able to create with it. But more importantly to me, it generates a rediculously long string, defines and resets color for every single character, uses both a color and bold escape sequence to use light/bright colors, mixes raw escape sequences and subshells running tput, and as a result is utterly unreadable and unmaintainable.
So, I replaced it:
{{{class="prettyprint"
### PROMPT ###
promptsetup() {
# Color definitions for prompt
local fg_brightred='\[$(tput setaf 9)\]'
local fg_blue='\[$(tput setaf 4)\]'
local fg_magenta='\[$(tput setaf 13)\]'
local fg_cyan='\[$(tput setaf 6)\]'
local fg_brightcyan='\[$(tput setaf 14)\]'
local reset='\[$(tput sgr0)\]'
# [hh:mm][username@hostname pwd]$
if [ -n "$SSH_CLIENT" ]; then
# Remotely, hostname is red.
PS1="${fg_blue}[\A]${fg_cyan}[${fg_brightcyan}\u${fg_cyan}@${fg_brightred}\h ${fg_cyan}\W]${reset}\$ "
elif [ -n "$VCSH_REPO_NAME" ]; then
# If in a vcsh repo env, add repo name in magenta.
PS1="${fg_blue}[\A]${fg_cyan}[${fg_brightcyan}\u${fg_cyan}@\h ${fg_magenta}$VCSH_REPO_NAME ${fg_cyan}\W]${reset}\$ "
else
# Locally, hostname is cyan.
PS1="${fg_blue}[\A]${fg_cyan}[${fg_brightcyan}\u${fg_cyan}@\h \W]${reset}\$ "
fi
}
promptsetup
}}}
I intentionally put everything in a function and call it immediately so I may use local vars for the color definitions. I didn't really want to leave them around just in case.
----
==Profile==
Bash chooses which dotfile to source based on how it gets run. If starting from a login shell, `~/.bash_profile` will get sourced, but if there's not a command in there to source your `~/.bashrc`, you may find yourself having to `exec bash` after starting bash. This can be fixed by adding the following line to your `~/.bash_profile`:
@ -70,33 +28,147 @@ The last thing of note in my `~/.bash_profile` is a warning:
----
==Weechat==
==Main bashrc==
The alias portion of my [[Weechat]] configuration is set in the .bashrc like so:
Things started getting a little too expansive, so I split off relevant sections into their own files. Now all my individual utilities have their own file, making troubleshooting and adding functionality much easier. You can find info for each file and what it does in its own section on this page.
===General config===
I'm not going in to detail about every line, but I'll hilight the important parts. The rest should be documented in the script itself.
First off, if we're not running bash interactively, there's no use for any of the rest of this, so just skip it.
{{{class="prettyprint"
# If you don't have weechat installed, connect to the existing tmux session through mosh
[[ ! -s /usr/bin/weechat ]] && alias weechat='mosh vps -- tmux attach -dt weechat'
# If you are thurstylark-vps, connect to the existing tmux session locally
[[ "$HOSTNAME" = "thurstylark-vps" ]] && alias weechat='tmux attach -dt weechat'
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
}}}
For more info, see the [[Weechat]] page.
Another cool option is actually built in to bash: If you call for a directory without any command before it, just `cd` into that directory.
{{{class="prettyprint"
# If a directory is given without any command, CD into it.
shopt -s autocd
}}}
This is where all the other utilities, aliases, and functions get pulled in. Anything in `~/.bashrc.d/` ending in `.sh` will get pulled in.
{{{class="prettyprint"
for f in ~/.bashrc.d/*.sh; do source "$f"; done
}}}
This also removes the need for the local bashrc sourcing that I [[https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc?id=30c53ca7224b583ed5068038b697653810e3b94b#n45|had in this file previously]]. If that functionality is needed, simply make a new script in `~/.bashrc.d/` and don't track it with `vcsh`.
Ordering can be done by adding numbers to the beginning of filenames. For example: `10-prompt.sh`. Currently, nothing that I use requires that kind of functionality.
----
==Prompt==
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/prompt.sh
I originally built my prompt using http://bashrcgenerator.com and, while it's a nice tool for visually building a prompt, it has several limitations on what you're able to create with it. But more importantly to me, it generates a rediculously long string, defines and resets color for every single character, uses both a color and bold escape sequence to use light/bright colors, mixes raw escape sequences and subshells running tput, and as a result is utterly unreadable and unmaintainable.
So, I replaced it:
{{{class="prettyprint"
promptsetup() {
# Color definitions for prompt
local fg_brightred='\[$(tput setaf 9)\]'
local fg_blue='\[$(tput setaf 4)\]'
local fg_magenta='\[$(tput setaf 13)\]'
local fg_cyan='\[$(tput setaf 6)\]'
local fg_brightcyan='\[$(tput setaf 14)\]'
local fg_green='\[$(tput setaf 2)\]'
local reset='\[$(tput sgr0)\]'
local hostname='\h'
local mixin
# [hh:mm][username@hostname pwd]$
# Remotely, hostname is red.
[ -n "$SSH_CLIENT" ] && hostname="${fg_brightred}\h${reset}"
# If in a python venv, add venv name in green.
[ -n "$VIRTUAL_ENV" ] && mixin=" ${fg_green}$(basename "$VIRTUAL_ENV")${reset}"
# If in a vcsh repo env, add repo name in magenta.
[ -n "$VCSH_REPO_NAME" ] && mixin=" ${fg_magenta}$VCSH_REPO_NAME${reset}"
PS1="${fg_blue}[\A]${fg_cyan}[${fg_brightcyan}\u${fg_cyan}@${hostname}${mixin} ${fg_cyan}\W]${reset}\$ "
}
promptsetup
}}}
I intentionally put everything in a function and call it immediately so I may use local vars for the color definitions. I didn't really want to leave them around just in case.
----
==Aliases==
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/alias.sh
Most of these are just creature comforts and fairly self-explanitory:
{{{class="prettyprint"
### ALIASES ###
# Colorize all `ls` output:
alias ls='ls -AF --color=auto'
# Map "la" to `ls -la`
alias la='ls -laFh --color=auto'
# Colorize `grep` output
alias grep='grep --color=auto'
# Change layout of lsblk to include FSTYPE and remove MAJ:MIN, RM, and RO collumns.
alias lsblk='lsblk -o NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT'
# Always use sudo when using nmap.
alias nmap='sudo -E nmap'
# Switch $TERM temporarily (for logging into machines that don't have tmux-256color terminfo)
alias screenterm='TERM=screen-256color'
}}}
----
==Colored man Pages==
Some color changes in `man` are almost essential for readability for me, so here's how I achieve that:
{{{class="prettyprint"
# Enables colored Man pages:
man() {
env LESS_TERMCAP_mb=$'\E[01;31m' \
LESS_TERMCAP_md=$'\E[01;38;5;74m' \
LESS_TERMCAP_me=$'\E[0m' \
LESS_TERMCAP_se=$'\E[0m' \
LESS_TERMCAP_so=$'\E[38;5;246m' \
LESS_TERMCAP_ue=$'\E[0m' \
LESS_TERMCAP_us=$'\E[04;38;5;146m' \
man "$@"
}
}}}
This can also be done for any similar program that uses `less` as its pager.
----
==Get Dell Service Tag==
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/getdst.sh
I work with Dell machines a lot, and when dealing with hardware problems, it's nice to have the service tag handy. Lucky for me, the service tag is easily retrieveable using `dmidecode(1)`, so I made a function for it.
{{{class="prettyprint"
# Print Dell Service Tag
getdst() {
if [[ "$1" = "-l" ]]; then
printf "http://www.dell.com/support/home/us/en/04/product-support/servicetag/%s\n" "$(getdst)"
else
sudo dmidecode -s system-serial-number
fi
if [[ "$1" = "-l" ]]; then
printf "http://www.dell.com/support/home/us/en/04/product-support/servicetag/%s/configuration\n" "$(getdst)"
else
sudo dmidecode -s system-serial-number
fi
}
}}}
@ -106,19 +178,22 @@ As an added bonus, the `-l` option will print the url for that product's support
==Screenshot==
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/shot.sh
This function wraps `maim(1)` and `fb(1)` to simplify my most used options. It uses maim to capture either the full screen, the active window, or a mouse selection to a file, or directly to a pastebin.
{{{class="prettyprint"
# Screenshot utils
shot() {
# Usage: shot XY
local destdir="$HOME/Pictures/screenshots"
local fname="shot-$(date +%F-%T).png"
local fname
local pb="fb"
local paste msgt msgd opts
fname="shot-$(date +%F-%T).png"
if [ -z "$1" ]; then
printf "Usage: shot XY
printf "
Usage: shot XY
X: Target
Y: Destination
@ -149,12 +224,11 @@ p Upload to a pastebin (defined in function)
msgt="mouse selection"
;;
*) printf "Unknown target: %s\n" "${1:0:1}"
*) printf "Invalid target: %s\n" "${1:0:1}"
return
;;
esac
#Y: Where to put the result
# Y: Where to put the result
case ${1:1:1} in
# Save to file
f) msgd="file: $destdir/$fname"
@ -164,7 +238,7 @@ p Upload to a pastebin (defined in function)
msgd="pastebin"
paste=1;;
*) printf "Unknown destination: %s\n" "${1:1:1}"
*) printf "Invalid destination: %s\n" "${1:1:1}"
return
;;
esac
@ -172,11 +246,13 @@ p Upload to a pastebin (defined in function)
# Make sure destination directory will exist
[[ ! -d "$destdir" ]] && mkdir -p "$destdir"
local fpath="${destdir}/${fname}"
# If target is active window, give a 5 second countdown before running maim
[[ "$msgt" = "active window" ]] && countdown 5
maim $opts "$fpath"
maim "$opts" "$fpath"
printf "Captured %s -> %s\n" "$msgt" "$msgd"
# If destination is a pastebin, do the needful
[[ "$paste" ]] && $pb "$fpath"
}
@ -189,12 +265,21 @@ This probably isn't the most robust solution, but it works pretty well. Patches
==Countdown==
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/countdown.sh
Found this little function when I wanted to add functionality to `shot()`. It takes an integer as an argument, then counts down that number of seconds visually.
{{{class="prettyprint"
countdown() {
if [ -z "$1" ]; then
printf "
countdown: Count down while printing progress on the terminal
Usage: countdown <seconds>
"
fi
local secs="$1"
while [ $secs -gt 0 ]; do
while [ "$secs" -gt 0 ]; do
echo -ne "$secs\033[0K\r"
sleep 1
: $((secs--))
@ -208,6 +293,8 @@ This probably isn't the sanest or safest solution to the problem, but it gets th
==FontFind==
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/fontfind.sh
Sometimes you just need to figure out what font provides a specific character. This function provides that solution:
{{{class="prettyprint"
@ -224,6 +311,8 @@ fontfind() {
==Vactivate==
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/vactivate.sh
I started needing more than one python virtualenv, and I wanted easy access to my own specific file structure. Additionally, I wanted the ability to deactivate the venv like I would exit a child shell. This is the solution that I came up with:
{{{class="prettyprint"
@ -237,4 +326,12 @@ vactivate() {
}
}}}
A caveat to this is that the prompt modification that venv usually applies is not available using this method. If a prompt modification is desired, it needs to be taken care of elsewhere.
A caveat to this is that the prompt modification that venv usually applies is not available using this method. If a prompt modification is desired, it needs to be taken care of elsewhere. I take care of it in my prompt setup detailed [[https://wiki.thurstylark.com/Bashrc.html#Prompt|here]].
----
==Weechat==
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/weechat.sh
See: [[Weechat]].

View File

@ -1,8 +0,0 @@
= Eudyptula Challenge =
From the [[http://eudyptula-challenge.org/|Eudyptula Challenge website]]:
"The Eudyptula Challenge is a series of programming exercises for the Linux kernel, that start from a very basic "Hello world" kernel module, moving on up in complexity to getting patches accepted into the main Linux kernel source tree."
== Tasks ==
1. [[Hello World]]

View File

@ -1,34 +0,0 @@
= Hello World =
=== Eudyptula Challenge: Task 1 ===
== Task Description ==
{{{
This is Task 01 of the Eudyptula Challenge
------------------------------------------
Write a Linux kernel module, and stand-alone Makefile, that when loaded
prints to the kernel debug log level, "Hello World!" Be sure to make
the module able to be unloaded as well.
The Makefile should be able to build the kernel module against the
source of the currently-running kernel as well as being able to accept
an arbitrary kernel sources directory from an environment variable.
Please show proof of this module being built, and running, in your
kernel. What this proof is is up to you. I'm sure you can come up with
something. Also be sure to send the kernel module you wrote, along with
the Makefile you created to build the module.
}}}
== Breakdown ==
* [X] Create Module that prints `Hello World!` to the kernel debug log level
* [X] Create Makefile to build your module
* [ ] Provide proof of this module being built and running in your kernel
== Notes ==
* `#include <linux/module.h>` Needed by all modules
* `#include <linux/kernel.h>` Needed for KERN_INFO
* `#include <linux/init.h>` Macros used to mark up functions e.g., __init __exit
*

View File

@ -5,9 +5,7 @@ Half brain dump, half documentation practice.
=== Projects ===
* [[Vimwiki]] -- This very wiki, and how it's hosted
* [[Eudyptula Challenge]]
* [[Cgit]] -- Configuration and hosting of https://git.thurstylark.com/
* [[Automating Android App Builds]] -- Documentation of my setup for building AsteroidOS Sync from https://www.github.com/asteroidos/AsteroidOSSync
* [[Audiobook RSS Feed]]
===Configuration/Dotfiles===