Last active
April 13, 2018 22:35
-
-
Save jdarpinian/991ecc7b69097516802ba5b2b0f36656 to your computer and use it in GitHub Desktop.
Essential Linux config file additions that should be the default
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Eternal bash history. | |
# --------------------- | |
# Undocumented feature which sets the size to "unlimited". | |
# http://stackoverflow.com/questions/9457233/unlimited-bash-history | |
export HISTFILESIZE= | |
export HISTSIZE= | |
export HISTTIMEFORMAT="[%F %T] " | |
# Change the file location because certain bash sessions truncate .bash_history file upon close. | |
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login | |
export HISTFILE=~/.bash_eternal_history | |
# Force prompt to write history after every command. | |
# http://superuser.com/questions/20900/bash-history-loss | |
PROMPT_COMMAND="history -a; $PROMPT_COMMAND" | |
# Disable flow control so Ctrl-s doesn't freeze the terminal | |
stty -ixon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set completion-ignore-case on | |
set show-all-if-ambiguous on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Share a single TCP connection for multiple SSH instances to the same server | |
ControlMaster auto | |
ControlPath ~/.ssh/socket-%r@%h-%p | |
# Keep TCP connections alive after SSH exits so the next connection is fast | |
ControlPersist 604800 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd "${0%/*}" # cd to directory containing this script | |
# Print time taken on exit. | |
export START=`date +%s` | |
trap 'EXIT_CODE=$?; set +ex; echo; echo Took $((`date +%s`-START)) second\(s\).; if [ $EXIT_CODE -ne 0 ]; then echo -e "\n---- ERROR ----\n"; fi' EXIT | |
# Echo all commands before execution and exit if any fail. | |
set -ex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Respond to SIGTERM by killing all child processes. | |
if [ "$1" != "--is-child" ]; then | |
set -m; "$0" --is-child "$*" & PGID=$(ps -p $! -o pgid=) | |
trap "exit" INT TERM;trap "pkill -g $PGID" EXIT;wait;exit | |
fi | |
shift |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Kill all other invocations of this script (and all their child processes) | |
# before starting. In order for this to work some hacks are needed. First, | |
# to uniquely identify this script, always invoke it with its exact full path | |
# according to realpath. Second, find other instances using pidof. Third, | |
# list all descendants of those processes and kill them all with SIGINT. | |
# Finally, we can continue into the real script below. | |
if [ "$0" != "$(realpath "$0")" ]; then "$(realpath "$0")" "$@"; exit; fi | |
descendants () { | |
local children=$(ps -o pid= --ppid "$1") | |
for pid in $children; do descendants "$pid"; done | |
echo "$children" | |
} | |
for pid in $(pidof -x "$0" -o $$); do kill -2 $pid $(descendants $pid); done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment