1
0
Fork 0

Cleanup bash settings

This commit is contained in:
J. Elfring 2024-11-02 13:54:41 +01:00
parent 4cd8f5fa80
commit a29852afeb
4 changed files with 5 additions and 174 deletions

View file

@ -1,9 +1,5 @@
#!/bin/bash #!/bin/bash
# debian specific aliases
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
# Easier navigation: .., ..., ...., ....., ~ and - # Easier navigation: .., ..., ...., ....., ~ and -
alias ..="cd .." alias ..="cd .."
alias ...="cd ../.." alias ...="cd ../.."
@ -39,79 +35,12 @@ alias less="less -R"
# Enable aliases to be sudoed # Enable aliases to be sudoed
alias sudo='sudo ' alias sudo='sudo '
# Get week number
alias week='date +%V'
# Stopwatch
alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date'
# IP addresses
alias pubip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="ip a | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | grep -v '172.17.'"
# View HTTP traffic
alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
# Canonical hex dump some systems have this symlinked # Canonical hex dump some systems have this symlinked
command -v hd > /dev/null || alias hd="hexdump -C" command -v hd > /dev/null || alias hd="hexdump -C"
# OS X has no `md5sum`, so use `md5` as a fallback
command -v md5sum > /dev/null || alias md5sum="md5"
# OS X has no `sha1sum`, so use `shasum` as a fallback
command -v sha1sum > /dev/null || alias sha1sum="shasum"
# Trim new lines and copy to clipboard
alias c="tr -d '\n' | xclip -selection clipboard"
# URL-encode strings
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'
# Intuitive map function
# For example, to list all directories that contain a certain file:
# find . -name .gitattributes | map dirname
alias map="xargs -n1"
# One of @janmoesens ProTip™s
for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
alias "$method"="lwp-request -m '$method'"
done
# Kill all the tabs in Chrome to free up memory
# [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description
alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill"
# Lock the screen (when going AFK)
alias afk="~/.bin/~/.bin/screenlock.sh"
# vhosts
alias hosts='sudo vim /etc/hosts'
# copy working directory
alias cwd='pwd | tr -d "\r\n" | xclip -selection clipboard'
# copy file interactive
alias cp='cp -i'
# move file interactive
alias mv='mv -i'
# untar
alias untar='tar xvf'
# Pipe my public key to my clipboard.
alias pubkey="more ~/.ssh/id.pub | xclip -selection clipboard | echo '=> Public key copied to pasteboard.'"
# Pipe my private key to my clipboard.
alias privkey="more ~/.ssh/id | xclip -selection clipboard | echo '=> Private key copied to pasteboard.'"
# vi == vim # vi == vim
alias vi='vim' alias vi='vim'
# vim w/ forced latin1
alias l1vim='vim -c "e ++enc=latin1"'
# Temperatursensoren mit Pfad # Temperatursensoren mit Pfad
alias get_systemp="paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) <(ls -1 /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t" alias get_systemp="paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) <(ls -1 /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t"
@ -124,5 +53,7 @@ alias y_rem='pikaur -Rsn'
# Passwort erstellen # Passwort erstellen
alias mkpasswd='openssl rand -base64 40 | cut -c1-40' alias mkpasswd='openssl rand -base64 40 | cut -c1-40'
# Copy latest Download into primary selection # Add an "alert" alias for long running commands. Use like so:
alias cld='cat $(ls --directory --format single-column -t --color=never ~/Downloads/* | head --lines 1) | xclip -in' # sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

View file

@ -25,54 +25,6 @@ case "$TERM" in
xterm-color) color_prompt=yes;; xterm-color) color_prompt=yes;;
esac esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# enable programmable completion features (you don't need to enable # enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc). # sources /etc/bash.bashrc).

View file

@ -5,8 +5,7 @@ which ruby >/dev/null 2>&1 && PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH"
export PATH=~/.local/bin:~/.bin:$PATH export PATH=~/.local/bin:~/.bin:$PATH
# Make vim the default editor # Make vim the default editor
export EDITOR=vim; export EDITOR=nvim;
export TERMINAL="alacritty";
export HISTSIZE=50000000; export HISTSIZE=50000000;
export HISTFILESIZE=$HISTSIZE; export HISTFILESIZE=$HISTSIZE;
@ -40,12 +39,3 @@ export LESS_TERMCAP_md="${yellow}";
export MANPAGER="less -X"; export MANPAGER="less -X";
export DBUS_SESSION_BUS_ADDRESS=unix:path=/var/run/user/$(id -u)/bus; export DBUS_SESSION_BUS_ADDRESS=unix:path=/var/run/user/$(id -u)/bus;
export TODOTXT_DEFAULT_ACTION=ls
export CM_LAUNCHER=rofi
# hidpi for gtk apps
#export GDK_SCALE=2
#export GDK_DPI_SCALE=0.5
#export QT_DEVICE_PIXEL_RATIO=2

View file

@ -45,24 +45,6 @@ fs() {
fi fi
} }
# Start an HTTP server from a directory, optionally specifying the port
server() {
local port="${1:-8000}"
sleep 1 && open "http://localhost:${port}/" &
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesnt break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
}
# Compare original and gzipped file size
gz() {
local origsize=$(wc -c < "$1")
local gzipsize=$(gzip -c "$1" | wc -c)
local ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l)
printf "orig: %d bytes\n" "$origsize"
printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio"
}
# Run `dig` and display the most useful info # Run `dig` and display the most useful info
digga() { digga() {
dig +nocmd "$1" any +multiline +noall +answer dig +nocmd "$1" any +multiline +noall +answer
@ -102,16 +84,6 @@ getcertnames() {
fi fi
} }
# `o` with no arguments opens the current directory, otherwise opens the given
# location
o() {
if [ $# -eq 0 ]; then
xdg-open . > /dev/null 2>&1
else
xdg-open "$@" > /dev/null 2>&1
fi
}
# Get colors in manual pages # Get colors in manual pages
man() { man() {
env \ env \
@ -125,20 +97,6 @@ man() {
man "$@" man "$@"
} }
# Use feh to nicely view images
openimage() {
local types='*.jpg *.JPG *.png *.PNG *.gif *.GIF *.jpeg *.JPEG'
cd $(dirname "$1")
local file=$(basename "$1")
feh -q $types --auto-zoom \
--sort filename --borderless \
--scale-down --draw-filename \
--image-bg black \
--start-at "$file"
}
# get the name of a x window # get the name of a x window
xname(){ xname(){
local window_id=$1 local window_id=$1