Skip to content

Instantly share code, notes, and snippets.

@ellemenno
Last active June 6, 2021 21:54
Show Gist options
  • Save ellemenno/9492550 to your computer and use it in GitHub Desktop.
Save ellemenno/9492550 to your computer and use it in GitHub Desktop.
The little tweaks I've accumulated and grown accustomed to.
# prompt (see https://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html)
# this prompt has 3 parts:
# 1. exit code indicator. test $? and print green ○ (U+25CB) for success (0), or red ● (U+25CF) for fail (non-zero)
# 2. current working directory. print \W in bold
# 3. UID indicator. \$ gives # for root, $ otherwise; print in bold
export PS1="\$([ \$? = 0 ] && echo '\[\e[32m\]○\[\e[0m\]' || echo '\[\e[31m\]●\[\e[0m\]') \[\e[1m\]\W \$ \[\e[0m\]"
# aliases (use `alias` to list)
alias ls="ls -hF"
alias l="ls -1"
alias ll="ls -la"
alias todo="grep 'TODO.*' --recursive --line-number --only-matching *"
alias fixme="grep 'FIXME.*' --recursive --line-number --only-matching *"
alias encrypt="openssl enc -e -aes-256-cbc -a -md sha256 -salt << EOM"
alias decrypt="openssl enc -d -aes-256-cbc -a -md sha256 << EOM"
# exports
export CLICOLOR=1 # let ls and git be colourful
export GREP_OPTIONS='--color=auto' # ask grep to highlight matches
export LSCOLORS=cxhxgefegxeghdabagacad # define terminal colors, see http://geoff.greer.fm/lscolors/
PATH=$PATH:~/bin # add user home bin to path
export PATH
# functions
# enable cd with history, from [acd_func.sh](http://linuxgazette.net/109/marinov.html)
source $HOME/bin/acd_func.sh
# cd with terminal title change
source $HOME/bin/title_func.sh
# piggy back on acd_func.sh to set title after changing directories
function cd_title {
cd_func "$@"
title $(basename `pwd`)
}
alias cd=cd_title
@ellemenno
Copy link
Author

@ellemenno
Copy link
Author

ellemenno commented Jan 7, 2019

on ubuntu, prefs are separated into .bash_aliases and .dircolors:

# exports (use `export -p` to list)

# prompt
# exit code indicator, current working directory, user level indicator
export PS1="\$([ \$? = 0 ] && echo '\[\e[32m\]○\[\e[0m\]' || echo '\[\e[31m\]●\[\e[0m\]') \[\e[1m\]\W \$ \[\e[0m\]"

# wsl specific
function winpath() {
  echo "$(cd /mnt/c && cmd.exe /C "echo | set /p _=%USERPROFILE%")" # chomp; see: https://stackoverflow.com/a/11336754/3029276
}
export WINHOME="$(wslpath -u $(winpath))" # convert from dos to nix; see: https://superuser.com/a/1340707/475734

# set visible bell. for windows terminal (wt.exe), the following needs to be set in ~/.inputrc
set bell-style visible # [none, audible, visible]

# chrome accetps url parameters to open
export BROWSER="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe"


# aliases (use `alias` to list)

alias cls="clear && printf \"\ec\"" # like CTRL-K for OSX, or CLS for DOS

alias ls='ls -hF --color=auto --show-control-chars'
alias l='ls -1'
alias ll='ls -la'

# url launcher (this masks openvt command)
alias open="$BROWSER"

# SP  ' '  0x20 = · U+00B7 Middle Dot
# TAB '\t' 0x09 = → U+FFEB Halfwidth Rightwards Arrow
# CR  '\r' 0x0D = ␍ U+240D symbol for carriage return
# LF  '\n' 0x0A = ␊ U+240A symbol for line feed
alias aparecium="sed 's/ /·/g;s/\t/→/g;s/\r/␍/g;s/$/␊/g'"

alias encrypt="openssl enc -e -aes-256-cbc -a -md sha256 -salt << 'EOM'"
alias decrypt="openssl enc -d -aes-256-cbc -a -md sha256 << EOM"

alias fixme='grep --perl-regexp --recursive --line-number --only-matching '\''FIXME:[^\015\012]*'\'' *'
alias todo='grep --perl-regexp --recursive --line-number --only-matching '\''TODO:[^\015\012]*'\'' *'

alias levelup='sudo apt update && sudo apt upgrade -y && sudo apt autoremove --purge && sudo apt clean'
alias wutos='lsb_release -d | sed '\''s/\S*\s*\(\.*\)/\1/'\''' # s/ word separator (rest-of-line) / capture-1 /

alias win="cd $WINHOME"
alias docs="cd $WINHOME/Documents"
alias box="cd $WINHOME/Dropbox"

alias glm="cd $WINHOME/Dropbox/gollum && ./run.sh"

# key bindings
#   see: https://www.computerhope.com/unix/bash/bind.htm
#   \C-? CTRL-?
#   \C-m ENTER
#   \e   ALT
bind '"\C-k"':"\"cls\C-m\"" # CTRL-K handled as sequence [c-l-s-<ENTER>], which runs the cls alias

# announce OS
wutos

.bash_aliases for WSL

# Configuration file for dircolors, a utility to help you set the
# LS_COLORS environment variable used by GNU ls with the --color option.
# Copyright (C) 1996-2016 Free Software Foundation, Inc.
# Copying and distribution of this file, with or without modification,
# are permitted provided the copyright notice and this notice are preserved.
# The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the
# slackware version of dircolors) are recognized but ignored.
# Below are TERM entries, which can be a glob patterns, to match
# against the TERM environment variable to determine if it is colorizable.
TERM Eterm
TERM ansi
TERM color-xterm
TERM con[0-9]*x[0-9]*
TERM cons25
TERM console
TERM cygwin
TERM dtterm
TERM eterm-color
TERM gnome
TERM gnome-256color
TERM hurd
TERM jfbterm
TERM konsole
TERM kterm
TERM linux
TERM linux-c
TERM mach-color
TERM mach-gnu-color
TERM mlterm
TERM putty
TERM putty-256color
TERM rxvt*
TERM screen*
TERM st
TERM st-256color
TERM terminator
TERM tmux*
TERM vt100
TERM xterm*
# Below are the color init strings for the basic file types.
# A color init string consists of one or more of the following numeric codes separated by semicolons:
#   Attribute:  00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
#   Text:       30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
#   Background: 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#NORMAL 00 # no color code at all
#FILE 00 # regular file: use no color at all
RESET 0                     # rs | reset to "normal" color
                            #  .-- https://geoff.greer.fm/lscolors/
DIR 34;01                   # di | directory
LINK 35;01                     # ln | symbolic link. (If you set this to 'target' instead of a
                            #      numerical value, the color is as for the file pointed to.)
SOCK 35;01                  # so | socket
FIFO 40;33                  # pi | pipe
EXEC 36;01                  # ex | file with execute permission
BLK 40;33;01                # bd | block device driver
CHR 40;33;01                # cd | character device driver
SETUID 41;37                # su | file that is setuid (u+s)
SETGID 43;30                # sg | file that is setgid (g+s)
STICKY_OTHER_WRITABLE 34;01 # tw | dir that is sticky and other-writable (+t,o+w)
OTHER_WRITABLE 34;01        # ow | dir that is other-writable (o+w) and not sticky
                            #  `-----------------------------------
MULTIHARDLINK 00            # mh | regular file with more than one link
DOOR 01;35                  # do | door
ORPHAN 40;31;01             # or | symlink to nonexistent file, or non-stat'able file ...
MISSING 00                  # mi   ... and the files they point to
CAPABILITY 41;30            # ca | file with capability
STICKY 34;01                # st | dir with the sticky bit set (+t) and not other-writable
# List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a '#')
# If you use DOS-style suffixes, you may want to uncomment the following:
#.cmd 01;32 # executables (bright green)
#.exe 01;32
#.com 01;32
#.btm 01;32
#.bat 01;32
# Or if you want to colorize scripts even if they do not have the
# executable bit actually set.
#.sh 01;32
#.csh 01;32

.dircolors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment