Skip to content

Instantly share code, notes, and snippets.

@weshouman
Last active November 1, 2023 13:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weshouman/19a681c99b0119e4eb6c to your computer and use it in GitHub Desktop.
Save weshouman/19a681c99b0119e4eb6c to your computer and use it in GitHub Desktop.
After installation todos #important #bash #linux #git
# I usually add a similar block to the .bashrc
####################################
##### My Stuff: Walid Shouman ####
####################################
# disable freezing, follow https://unix.stackexchange.com/a/72092/310075
stty -ixon
#~~~~~~~~~~~~~~~~~~~~~~~#
## Custom Shortcuts ##
#~~~~~~~~~~~~~~~~~~~~~~~#
# left ctrl + up and down will match exact keyword from beginning
# We don't overwrite the original up and down to allow navigating around the matched commands freely
bind '"\e[1;5A": history-search-backward'
bind '"\e[1;5B": history-search-forward'
#~~~~~~~~~~~~~~~~~~~~~~~#
## Append Line By Line ##
#~~~~~~~~~~~~~~~~~~~~~~~#
shopt -s histappend
PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
#~~~~~~~~~~~~~~~~~~~~#
## Custom Variables ##
#~~~~~~~~~~~~~~~~~~~~#
# Generic Development
export prosrc="/home/$USER/Documents/projects/pro"
# Open BCI Development
export obsrc="/home/walid/Documents/tests/braingizer/openbci"
# MyMongo Development (testing rails with MongoDB)
export mymongosrc="/home/$USER/Documents/tests/mymongo"
# Atman Development
export atmsrc="/home/walid/Documents/atm/atman"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
## Productivity Alias Variables ##
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
alias c='xclip -selection clipboard'
alias v='xclip -o'
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
## Productivity Alias Functions ##
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Reference: make bash alias that takes parameter
# http://stackoverflow.com/a/7131683/2730737
# ```mkdir -p``` makes dirs recursively
my_mkdir_and_cd_function() {
mkdir -p $1
cd $1
}
alias mkdircd=my_mkdir_and_cd_function
qq_java_search() {
apt-cache search $@ | grep java
}
# qq_lambda could be replaced by using xargs
# for example:
# find ~/Documents | grep pdf | xargs -n1 ls -l
# Usage:
# qq_lambda "$(find ~/Documents | grep pdf)" "ls -l $i"
qq_lambda() { for i in "$1"; do eval ${2}; done; }
#~~~~~~~~~~~~~~~~~~~~#
## Source if exists ##
#~~~~~~~~~~~~~~~~~~~~#
# Usage: source_if_exists ~/.bashrc_custom_k3s
source_if_exists() {
local script="$1"
if [ -f "$script" ]; then
. "$script"
fi
}
# Usage: source_if_exists_dir ~/.bashrc_custom.d/
# source_if_exists_dir ~/.bashrc_custom.d/ "*.bak|*.tmp"
source_if_exists_dir() {
local dir="$1"
local exclude_pattern="$2" # Optional second argument to specify patterns to exclude
if [ ! -d "$dir" ]; then
# silent by default
#echo "Directory not found: $dir"
return 1
fi
for script in "$dir"/*; do
if [ -f "$script" ]; then
# Extract just the filename from the full path
local filename=$(basename "$script")
# Skip files that match the exclude pattern
if [[ -n "$exclude_pattern" ]]; then
case "$filename" in
$exclude_pattern)
continue
;;
esac
fi
source "$script"
fi
done
}
source_if_exists_dir ~/.bashrc_custom.d/ "*.manual"
source_if_exists_dir ~/.bash_completion.d/
#~~~~~~~~~~~~~~~~~~~~~~~~~~#
## Kubernetes Development ##
#~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Hint: use
# DEP=deployment-name && mypods $DEP
# or
# DEP=deployment-name
# watch -x bash -c 'mypods $DEP'
# Note that we are using the default namespace
mypods() {
kubectl get po | grep $1 | \awk '{print $1;}'
}
# A script to get the namespace of a specific release
# helm-find-release RELEASE_NAME
alias helm-find-release="function _helm_find_release() { release_name=\$1; for ns in \$(kubectl get ns -o jsonpath='{.items[*].metadata.name}'); do helm list -n \$ns | grep \$release_name &> /dev/null && echo \"Release \$release_name found in namespace \$ns\"; done; }; _helm_find_release"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
## Ruby on Rails Development ##
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Use rvm directly
source /home/$USER/.rvm/scripts/rvm
# if the previous one didn't work, try any of the following two options
# source /usr/local/rvm/scripts/rvm
# source /usr/share/rvm/scripts/rvm
# Add RVM to PATH for scripting
export PATH="$PATH:$HOME/.rvm/bin"
#~~~~~~~~~~~~~~~~~~~~~~~#
## SystemC Development ##
#~~~~~~~~~~~~~~~~~~~~~~~#
export SYSTEMC_HOME="/usr/local/systemc231"
export LD_LIBRARY_PATH="/usr/local/systemc-2.3.1/lib-linux"
#~~~~~~~~~~~~~~~~~~~~~~~#
## ARDUINO DEVELOPMENT ##
#~~~~~~~~~~~~~~~~~~~~~~~#
# Usage
# export ARDCONF="/home/${USER}/Arduino/conf/arduino-cli.yaml";
# qq_arduino-cli config dump # or any other arduino-cli command
qq_arduino-cli() { arduino-cli $@ --config-file "${ARDCONF}"; }
qq_arduino-cli_debug() { echo arduino-cli $@ --config-file \"${ARDCONF}\"; }
#~~~~~~~~~~~~~~~~~~~~~#
## Search Utilities ##
#~~~~~~~~~~~~~~~~~~~~~#
# For further understanding, follow this [reference](http://offbytwo.com/2011/06/26/things-you-didnt-know-about-xargs.html)
# number of cores
CORES=4
# caught ANOMALY
# when there's binary file, the counting and file listing will work pretty good, but showing the exact occurances won't work!
# Not sure about sed in this case xD
# TODO: make the opinionated grep show the number of occurances and the file names too!
# find in all non-hidden files
# USAGE: mygrep "some_string"
mygrep() { find * -type f | xargs -n1 -P${CORES} grep $@; }
# find in all hidden and non-hidden files
# USAGE: mygrepa -li "some_string"
# mygrepa "some_string"
mygrepa() { find . -type f | xargs -n1 -P${CORES} grep $@; }
# NOTE: OPINIONATED
# mygrep series uses the xargs, thus counting will be per file which is usually not desired, thus mycgrep exists for that
mycgrep() { mygrepa -c $@ 2>/dev/null | awk '{s+=$1} END {print s}'; }
# NOTE: VERY OPINIONATED
# my opinionated grep
myogrep() { mygrepa -B3 -A2 --group-separator================ $@ 2>/dev/null; }
# find all files containing the given string
locstr() { mygrep -l $@; }
locstra() { mygrepa -l $@; }
# makes a backup file and replaces files in place
# USAGE: myosed oldstr newstr
# doesn't replace hidden files, for a bit of safety `:D
myosed() { locstr '$1' 2>/dev/null | xargs -i@ sed -ibak 's/$1/$2/g' @; }
# find through git commits, follow https://stackoverflow.com/a/2929502
# Usage: gitgrep WcResolution
# gitgrep WcResolution docs/Commands.md
gitgrep() {
if [ $# -eq 1 ]; then
git grep $1 $(git rev-list --all);
else
git grep $1 $(git rev-list --all -- $2) -- $2;
fi
}
#~~~~~~~~~~~~~~~~~~~~~#
## Uncategorized yet ##
#~~~~~~~~~~~~~~~~~~~~~#
# Custom bin file
export PATH="$PATH:~/bin"
# Call using `journalback "1 day ago" -u myservice.service -f`
journalback() {
time_ago ="$1"
shift # Shift arguments to the left. $2 becomes $1, $3 becomes $2, etc.
journalctl --since="$(date -d "$time_ago" '+%Y-%m-%d %H:%M:%S')" "$@"
}
#~~~~~~~~~~~~~~~~~~~~~~~#
## Virtualenv Utils ##
#~~~~~~~~~~~~~~~~~~~~~~~#
VENV_DIR=venv
# create a virtualenv in ./VENV_DIR
alias c_venv="virtualenv -p python3 ${VENV_DIR}"
alias cs_venv="c_venv --system-site-packages"
# start a virtualenv in ./VENV_DIR
alias s_venv="source ${VENV_DIR}/bin/activate"
# end a virtualenv in ./VENV_DIR
alias e_venv="deactivate"
#~~~~~~~~~~~~~~~~~~~~~~~#
## FS Diff Utils ##
#~~~~~~~~~~~~~~~~~~~~~~~#
# Usage:
# 1. Create a script.sh file with the content you want to execute
# 2. Run diff_sizes script.sh
# or
# 2. Run diff_sizes_and_dates script.sh
PRE_DU=sizes_before.du
POST_DU=sizes_after.du
diff_sizes() { du -ab | grep -Pv "^0\t" | grep -Pv "[0-9]+\t./(${PRE_DU})|(${POST_DU})" >${PRE_DU}; $1; du -ab | grep -Pv "^0\t" | grep -Pv "[0-9]+\t./(${PRE_DU})|(${POST_DU})+" >${POST_DU}; diff ${PRE_DU} ${POST_DU}; };
alias file_sizes_and_dates="find . -type f -exec ls -al {} + | awk {'printf(\"%8s\t%s %2s %5s %s\n\",\$5,\$6,\$7,\$8,\$9)'}"
diff_sizes_and_dates() { file_sizes_and_dates | grep -Pv "^\s*0\t" | grep -Pv " ./(${PRE_DU})|(${POST_DU})$" >${PRE_DU}; $1; file_sizes_and_dates | grep -Pv "^\s*0\t" | grep -Pv " ./(${PRE_DU})|(${POST_DU})$" >${POST_DU}; diff ${PRE_DU} ${POST_DU}; };
#~~~~~~~~~~~~~#
## SSH Utils ##
#~~~~~~~~~~~~~#
# keep retrying to connect to host until it's running again
# Usage
# qq_ssh_sticky user@192.168.12.100
# Interactive oneliner
# _sticky_ssh() { while true; do command ssh "$@"; [ $? -eq 0 ] && break || sleep 0.5; done; }
qq_ssh_sticky() {
while true; do
command ssh "$@"; [ $? -eq 0 ] && break || sleep 0.5;
done;
}
#~~~~~~~~~~~~~#
## PDF Utils ##
#~~~~~~~~~~~~~#
# Usage
# qq_pdf_shrink source.pdf destination.pdf
# Interactive oneliner
# _pdf_shrink() { gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$2 $1; }
qq_pdf_shrink() {
gs -sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/ebook \
-dNOPAUSE \
-dQUIET \
-dBATCH \
-sOutputFile=$2 \
$1;
}
#~~~~~~~~~~~~~~~~#
## Productivity ##
#~~~~~~~~~~~~~~~~#
# Usage
# qq_alarm 400 200
qq_alarm() { ( \speaker-test --frequency $1 --test sine )& pid=$!; \sleep 0.${2}s; \kill -9 $pid; }
#~~~~~~~~~~~~#
## Security ##
#~~~~~~~~~~~~#
# Usage
# qq_ls_cacert
qq_ls_cacert() {
awk -v cmd='openssl x509 -noout -subject' \
'/BEGIN/{close(cmd)};{print | cmd}' < /ETC/SSL/CERTS/CA-certificates.crt;
}
#~~~~~~~~~~~~#
## Docker ##
#~~~~~~~~~~~~#
# Usage: qq_docker_history IMAGE_TAG
qq_docker_image_layers() { docker history $@ --format "{{.CreatedBy}}" --no-trunc; }
####################################
## End of My Stuff: Walid Shouman ##
####################################
# my gitconfig options
[user]
email = my@email.com
name = Walid Shouman
[alias]
co = checkout
ci = commit
st = status
br = branch
dc = diff --cached
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
type = cat-file -t
dump = cat-file -p
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Example: git fame Walid
# Description: display number of commits that are authored
# by an author with the name including "Walid"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
fame = "!f() { git rev-list --all --count --author=\""$1"\"; }; f"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Example: git contribution Walid
# Description: display the commits that are authored
# by an author with the name including "Walid"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
contribution = "!f() { git shortlog --author=\""$1"\"; }; f"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Example: git ag "cleanup"
# Description: TBD
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
ag = "!f() { git log --all --grep=\""$1"\"; }; f"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Example: git ag-author "cleanup" "Walid"
# Description: TBD, old comments: not working
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
ag-author = "!f() { git log -all --grep=\""$1"\" --author=\""$2"\"; }; f"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Example: git branches
# Description: TBD
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
branches = "!f() { git for-each-ref --sort=committerdate refs/remotes/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'; }; f"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Example: git abbrev
# Description: TBD
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
abbrev = "!f() { git -c 'user.cmdline=true' config --list --show-origin; }; f"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Example: git fame Walid
# Description: TBD, old comments: this one was a hack
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# fame = "!f() { git log | grep -o "$1" | wc -l; }; f"
# mouse setup
set -g mouse on
set-window-option -g xterm-keys on
# copy to clipboard: ctrl+b > [ > ctrl+space > select > y
bind -T copy-mode y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
" I recommend using ~/.vim/plugin/custom.vim insead of ~/.vimrc to avoid removing any other defaults like syntax highlighting
" If any value here is not working, then it's overwritten by some other plugin, usually an ftplugin, to check that out run:
" verbose set shiftwidth ?
" Allow saving of files as sudo when I forgot to start vim using sudo.
" use by typing :w!!
" follow https://stackoverflow.com/a/7078429
cmap w!! w !sudo tee > /dev/null %
" Show tabs and spaces, follow https://vi.stackexchange.com/a/430
set list
" short for set listchars
set lcs=tab:␉─,trail:␠,nbsp:⎵
" Use the following to change the tab width to 2 and use spaces
set tabstop=2 shiftwidth=2 expandtab
"set softtabstop=-1 " that could be useful based on https://stackoverflow.com/questions/56408989/set-tab-as-2-spaces-in-vimrc-but-still-set-to-4-spaces-when-editing-python-file#comment121718552_56409189
" after installing securemodelines.vim
" from: https://www.vim.org/scripts/script.php?script_id=1876
" to: ~/.vim/plugin/
let g:secure_modelines_allowed_items = [
\ "syntax",
\ "textwidth", "tw",
\ "softtabstop", "sts",
\ "tabstop", "ts",
\ "shiftwidth", "sw",
\ "expandtab", "et", "noexpandtab", "noet",
\ "filetype", "ft",
\ "foldmethod", "fdm",
\ "readonly", "ro", "noreadonly", "noro",
\ "rightleft", "rl", "norightleft", "norl",
\ "spell",
\ "spelllang"
\ ]
" Tab management
" Guide: https://www.techrepublic.com/blog/linux-and-open-source/use-tabs-to-open-multiple-files-in-vim/
" Source: https://superuser.com/a/1372732/682757
" tab navigation: Alt or Ctrl+Shift may not work in terminal:
" http://vim.wikia.com/wiki/Alternative_tab_navigation
" Tab navigation like Firefox: only 'open new tab' works in terminal
nnoremap <C-t> :tabnew<CR>
inoremap <C-t> <Esc>:tabnew<CR>
" move to the previous/next tabpage.
nnoremap <C-j> gT
nnoremap <C-k> gt
" Go to last active tab
au TabLeave * let g:lasttab = tabpagenr()
nnoremap <silent> <c-n> :exe "tabn ".g:lasttab<cr>
vnoremap <silent> <c-n> :exe "tabn ".g:lasttab<cr>
map <C-h> :tabrewind<cr>
map <C-l> :tablast<cr>
map <C-x> :tabclose<cr>
" Install Prosession plugin (alongside with the core ObSession) to save vim sessions
" cd ~/.vim/plugin
" git clone git://github.com/tpope/vim-obsession.git
" git clone git://github.com/dhruvasagar/vim-prosession.git
" vim -u NONE -c "helptags vim-obsession/doc" -c q
" vim -u NONE -c "helptags vim-prosession/doc" -c q
" Obsession usage: type ```:Obsess /optional/dir/or/session_name``` then load it ```vim -S session_name```
" Prosession usage: type ```:Prosession /dir/to/edit```, running vim from a pre-prosessioned will autoload the session
" Generic note: Close vim using ```:qa``` otherwise the last closed window/tab only will be saved
" Show file options above the command line
" For fuzzy searching multiple files
" Follow https://gist.github.com/csswizardry/9a33342dace4786a9fee35c73fa5deeb
set wildmenu
  • update software till you finish the following steps

  • enable receiving files over bluetooth

  • from dash open personal file sharing

  • check receives files in downloads folder over bluetooth

  • check notify about received files

  • system-settings:

  • add Arabic/Japanese

  • make changing language through Alt+Shift

  • remove Keyboard settings->Shortcuts->Windows->Minimize Window

  • Install Japanese -- choose Japanese Mozc (Google's) or Anthy (mature) from the text entry options

  • Make English main regional format

  • Enable workspaces

  • Show the menus for a window->in the window's title bar

  • When the led is closed do nothing

  • Turn screen of when in active for never

  • files:

  • .bashrc: change HISTFILESIZE from 2000 to 20000

  • change the history to append each line by line by adding the following lines in .bashrc

shopt -s histappend
PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
  • .bash_aliases: take a copy of any of the old ones

  • install firefox extension:

  • readlater

  • install some apps

  • git

  • synaptic

  • vim

  • dconf-editor (edit system configurations)

  • remove unused partitions/apps from launcher

  • install nvidia's things either

  • install prime-indicator -- if u ever the quickswitcher doesn't work ... and needs a real restart, try the following -- sudo prime-select nvidia -- sudo prime-select intel -- then try the quick switch (that solved it for me) or

  • purge the proprietary driver

  • install bumblebee

  • start bootcharting

  • sudo apt-get install bootchart pybootchartgui

  • then reboot

  • check them in /var/log/bootchart/*.png

  • setup open in terminal

  • sudo apt-get install nautilus-open-terminal

  • then reset nautilus with: nautilus -q

  • manage users/groups through ui

  • install gnome-system-tools through the software center

  • from start choose "Users and Groups"

  • add custom apps to the dash -- nano ~/.local/share/applications/blender272.desktop -- type the following/edit where needed

[Desktop Entry]
Name=Blender 2.72
Comment=
Exec=/home/walid5/Documents/blender/blender-2.72-RC1-linux-glibc211-x86_64/blender
Icon=/home/walid5/Documents/blender/blender-2.72-RC1-linux-glibc211-x86_64/icons/48x48/apps/blender.png
Terminal=false
Type=Application
StartupNotify=true

-- check this for more info http://askubuntu.com/a/112812

  • change the file association
    -- change the defaults.list in /usr/share/gnome/applications/defaults.list -> /etc/gnome/defaults.list
    sudo nano /etc/gnome/defaults.list -- add a line similar to the following (notice that we've used the blender272.desktop that we've just registered before)
    application/x-blender=blender272.desktop
    -- check this for more info http://askubuntu.com/questions/289337/how-can-i-change-file-association-globally -- someone used this xdg-mime and update-desktop-database http://crunchbang.org/forums/viewtopic.php?id=8451

  • install makerware -- sudo apt-add-repository 'deb http://downloads.makerbot.com/makerware/ubuntu trusty main' -- sudo apt-get update -- sudo apt-get install makerware

  • install sketchup using wine -- install wine (winex.x supports 64 and 32 arch, winex.x-amd64 supports only 64) -- add /DisableRubyAPI to the command in the desktop shortcut or use wine "/path/to/sketchup.exe" "/DisableRubyAPI" to open sketchup

  • change desktop font (use get first if you're not sure), could dconf-editor for that -- gsettings set org.gnome.nautilus.desktop font 'Ubuntu Bold 10'

  • change all fonts -- gsettings set org.gnome.desktop.interface font-name 'Ubuntu 9'

  • install rabbitvcs -- sudo apt-get install rabbitvcs-nautilus-3.0 -- nautilus -q && nautilus &

  • install systemc

  • use the gist for that

  • install etckeeper to track /etc changes

  • follow this guide

Install tree

Usefull to watch directory contents

sudo apt-get install tree
# usage example
# tree Documents -L 2

Install xclip

Useful for clipboard interaction with the shell

sudo apt-get install xclip

Add the following to .bashrc

alias "c=xclip"
alias "v=xclip -o"

Now we can copy to clipboard using pwd| c and paste from it using cd `v`
ref: Stackoverflow answer for How can I copy the output of a command directly into my clipboard?

Install VIM plugins

  • Download the securemodelines.vim from here
  • Move it into .vim/plugin
" Save this file in ~/.vim/after/ftplugin/python.vim
" (to overwrite the settings of the file ~/.vim/ftplugin/python.vim)
" This is a more elaborate version of the sets in the custom.vim, follow https://stackoverflow.com/a/14174779/2730737
set shiftround " Round indent to multiple of 'shiftwidth'
set smartindent " Do smart indenting when starting a new line
set autoindent " Copy indent from current line, over to the new line
" Set the tab width
let s:tabwidth=2
exec 'set tabstop=' .s:tabwidth
exec 'set shiftwidth=' .s:tabwidth
exec 'set softtabstop='.s:tabwidth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment