187 lines
8.3 KiB
Plaintext
187 lines
8.3 KiB
Plaintext
=Bashrc=
|
|
|
|
Source: https://git.thurstylark.com/vcsh/bashrc.git
|
|
|
|
==Profile==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bash_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`:
|
|
|
|
{{{class="prettyprint"
|
|
[[ -f ~/.bashrc ]] && . ~/.bashrc
|
|
}}}
|
|
|
|
I also use `~/.bash_profile` for setting numlock while in a tty:
|
|
|
|
{{{class="prettyprint"
|
|
case $(tty) in /dev/tty[0-9]*)
|
|
setleds -D +num # (numlock for X is set in ~/.xinitrc)
|
|
;;
|
|
esac
|
|
}}}
|
|
|
|
The last thing of note in my `~/.bash_profile` is a warning:
|
|
|
|
{{{class="prettyprint"
|
|
# Temporary fix for a systemd bug related to systemd --user timers that run on login
|
|
[[ -z "$DBUS_SESSION_BUS_ADDRESS" ]] && printf "%bWARNING: \$DBUS_SESSION_BUS_ADDRESS is unset! %b\n" "$(tput bold)$(tput setab 1)" "$(tput sgr0)"
|
|
}}}
|
|
|
|
----
|
|
|
|
==Main bashrc==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc
|
|
|
|
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 not running interactively, don't do anything
|
|
[[ $- != *i* ]] && return
|
|
}}}
|
|
|
|
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/12-prompt.bash
|
|
|
|
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 with my own setup that generates the needed color codes on the fly to improve readability. 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.
|
|
|
|
I'm not completely happy with this solution because it causes each of the tput subshells to execute each time the prompt is printed. I would like to change this to quash the extra output this causes when using `bash -x`, but I would also like to find a solution that minimizes so many subshells just for a prompt, but avoid hard-coding colors so it can be general enough to support any env in which it may be used.
|
|
|
|
----
|
|
|
|
== Environment ==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/11-env.bash
|
|
|
|
Here is where I set a few environment variables that are useful in one way or another, such as `HISTCONTROL`, `EDITOR`, `LS_COLORS`, and `LIBVIRT_DEFAULT_URI`.
|
|
|
|
----
|
|
|
|
==Aliases==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/10-alias.bash
|
|
|
|
Most of these are simple creature comforts and are commented with sufficient explanation.
|
|
|
|
----
|
|
|
|
== Pkgfile as `command_not_found_handle()` ==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/pkgfile.bash
|
|
|
|
This sets up `bash`'s `command_not_found_handle()` functionality so that when a command cannot be found in `PATH`, it will use `pkgfile` to check for that command in its databases, which are derived from the same [[https://wiki.archlinux.org/title/Pacman#Search_for_a_package_that_contains_a_specific_file|databases that `pacman -F` uses.]]
|
|
|
|
To keep these databases updated, `pkgfile` ships [[https://wiki.archlinux.org/title/Pkgfile#Automatic_updates|a systemd timer]] that runs the update command daily.
|
|
|
|
----
|
|
|
|
==Colored man Pages==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/colored-man-pages.bash
|
|
|
|
Some color changes in `man` are almost essential for readability for me, so I define my own.
|
|
|
|
This can be replicated for any similar program that uses `less` as its pager.
|
|
|
|
----
|
|
|
|
==Screenshot==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/shot.bash
|
|
|
|
`shot()` used to be much more complicated, but after moving to sway, I found that I couldn't be arsed to reimplement all of its former functionality. It turned out that the majority of the time, I want to select a region, and put it on stdout to be dealt with how I please. If I find that full-screen or all-screen screenshots are more useful to me in the future, I'll cross that bridge when I come to it.
|
|
|
|
|
|
----
|
|
|
|
==Countdown==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/countdown.bash
|
|
|
|
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.
|
|
|
|
I no longer use `countdown()` from `shot()` directly, but sometimes will in some sort of pipeline in tandem with it. I found that I want that flexibility out in the open for me to use instead of packed behind a bespoke ui for little benefit.
|
|
|
|
----
|
|
|
|
== cmdcopy ==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/cmdcopy.bash
|
|
|
|
This tool runs the specified command, capturing `stdout` and `stderr`, adds the specified command to the beginning of the output, and sends the result to stdout. The output of this command should be suitable to pipe directly into a paste service such as [[http://ix.io|ix.io]] when seeking support via IRC or other text-based method.
|
|
|
|
----
|
|
|
|
==Vactivate==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/vactivate.bash
|
|
|
|
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.
|
|
|
|
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#Bashrc-Prompt|here]].
|
|
|
|
----
|
|
|
|
==FontFind==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/fontfind.bash
|
|
|
|
Sometimes you just need to figure out what font provides a specific character. This function provides that solution.
|
|
|
|
----
|
|
|
|
== Resolve IP Addresses to MAC Addresses with `arping` ==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/arpresolve.bash
|
|
|
|
This utility comes in handy when I just want a MAC address as a string without having to dig through `nmap` output for it.
|
|
|
|
Unfortunately not all devices are cooperative to this method, so ymmv.
|
|
|
|
----
|
|
|
|
==Get Dell Service Tag==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/getdst.bash
|
|
|
|
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.
|
|
|
|
As an added bonus, the `-l` option will print the url for that product's support page.
|
|
|
|
----
|
|
|
|
==Weechat==
|
|
|
|
https://git.thurstylark.com/vcsh/bashrc.git/tree/.bashrc.d/weechat.bash
|
|
|
|
See: [[Weechat]].
|