Some of my scripts (bashrc, ...)
- bashrc
- ...
| # TARGET_FILE=~/.bashrc | |
| ## | |
| ## Basic configuration | |
| ## | |
| [[ -f ~/.profile ]] && . ~/.profile | |
| eval "$(dircolors -b ~/.config/.dircolors)" | |
| EDITOR=nano | |
| TERM=xterm-256color | |
| export LANG="en_US.UTF-8" | |
| export LESSHISTFILE="-" | |
| export HISTFILE="$HOME/.config/.bash_history" | |
| export BAT_THEME="GitHub" | |
| # Sqlite Configuration | |
| alias sqlite='sqlite3 -init ~/.config/sqlite/sqliterc' | |
| ## | |
| ## Imports | |
| ## | |
| source /usr/share/fzf/key-bindings.bash | |
| source ~/Develop/Scripts/dell-xps13-9350/colors.sh | |
| source /usr/share/git/git-prompt.sh | |
| [[ -r "/usr/share/z/z.sh" ]] && source /usr/share/z/z.sh | |
| ## | |
| ## Aliases | |
| ## | |
| # main aliases | |
| alias ls='ls --color=auto --group-directories-first -CX' | |
| alias lv='ls -1 --color=auto --group-directories-first -X' | |
| alias ll='ls --color=auto --group-directories-first -AlhXG' | |
| # prefer colored commands | |
| alias grep='grep --color=auto' | |
| alias egrep='egrep --color=auto' | |
| alias fgrep='fgrep --color=auto' | |
| alias tree='tree -C -L 2' | |
| alias ssh='TERM=xterm-256color ssh' | |
| # more interactive file manipulations | |
| alias rm='rm -Iv' | |
| alias mv='mv -iv' | |
| alias cp='cp -iv' | |
| # misc | |
| alias df='df -h' | |
| alias free='free -m' | |
| alias ..='cd ..' | |
| alias ...='cd ../..' | |
| alias ....='cd ../../..' | |
| alias .....='cd ../../../..' | |
| alias ......='cd ../../../../..' | |
| # showing and openning files | |
| alias show='bat --style "plain,header,grid" --pager "less -RF"' | |
| alias less='less -F' | |
| alias more='less -F' | |
| alias subl='subl -n' | |
| function open() { | |
| # opens a file with the default program without cluttering the terminal with its output. | |
| (xdg-open "$*" 2>&1) >/dev/null | |
| } | |
| function search() { | |
| open $(find . -not -path '*/\.*' -not -path '*/node_modules/*' -not -path './Develop*' -not -path './Downloads*' | fzf) | |
| } | |
| function cdmk() { | |
| mkdir -p "$1" | |
| cd "$1" | |
| } | |
| # package Managers | |
| alias pacman='pacman --color=auto' | |
| alias yay='yay --color=auto' | |
| # fix "sudo" completion | |
| alias sudo='sudo ' | |
| ## | |
| ## Custom Prompt | |
| ## | |
| # Python VirtualEnv | |
| export VIRTUAL_ENV_DISABLE_PROMPT=1 | |
| __virtualenv_ps1() { | |
| if [[ -n "$VIRTUAL_ENV" ]]; then | |
| venv="$(basename "$(dirname "$VIRTUAL_ENV")")/$(basename "$VIRTUAL_ENV")" | |
| else | |
| venv='' | |
| fi | |
| [[ -n "$venv" ]] && printf "$1" "$venv" | |
| } | |
| PS1_TEMPLATE_FILE=~/Develop/Scripts/dell-xps13-9350/ps1.js | |
| PS1_FILE=~/.cache/bash_ps1 | |
| PS1_GENERATE_CMD="node $PS1_TEMPLATE_FILE" | |
| if [[ ! -e "$PS1_FILE" || "$PS1_TEMPLATE_FILE" -nt "$PS1_FILE" ]]; then | |
| eval "$PS1_GENERATE_CMD" > $PS1_FILE | |
| fi | |
| export GIT_PS1_SHOWDIRTYSTATE=1 | |
| PS1=$(cat $PS1_FILE) | |
| # Dynamically set the window title | |
| function set_title () { | |
| echo -ne "\033]0;${@}\007" | |
| } | |
| # On command end | |
| export PROMPT_COMMAND=${PROMPT_COMMAND}'set_title "$PWD"' | |
| # On command start | |
| trap 'set_title "$BASH_COMMAND"' DEBUG | |
| #!/bin/bash | |
| # Cleans unlinked dotfiles in all used folders | |
| # | |
| # Author: aziis98 | |
| # Date: 06/01/2021 | |
| set -euo pipefail | |
| TRACKED_DOTFILES_FILE=~/.cache/dotfiles/tracked | |
| if [[ ! -e "$TRACKED_DOTFILES_FILE" ]]; then | |
| echo -e "Run \"dotfiles_link\" at least once to start tracking symlinks!" | |
| exit 1 | |
| fi | |
| DELETE_COUNT=0 | |
| while read tracked_file; do | |
| if [[ ! -e "$tracked_file" ]]; then | |
| DELETE_COUNT=$(($DELETE_COUNT + 1)) | |
| sed -i "\|$tracked_file|d" $TRACKED_DOTFILES_FILE | |
| rm -v "$tracked_file" | |
| fi | |
| done < "$TRACKED_DOTFILES_FILE" | |
| echo "Deleted $DELETE_COUNT broken link"$([[ "$DELETE_COUNT" -ne 1 ]] && echo -e "s") |
| #!/bin/bash | |
| # Links all files marked with "TARGET_FILE=..." to their target location | |
| # | |
| # Author: aziis98 | |
| # Date: 06/01/2021 | |
| set -euo pipefail | |
| TRACKED_DOTFILES_FILE=~/.cache/dotfiles/tracked | |
| mkdir -p "$(dirname "$TRACKED_DOTFILES_FILE")" | |
| # Extract a TSV table of SOURCE_FILE and TARGET_FILE | |
| grep -e "^# TARGET_FILE=" -r . | sed -e 's/:# TARGET_FILE=/\t/g' | \ | |
| while read line; do | |
| SOURCE_FILE="$(echo "$line" | cut -f1)" | |
| TARGET_FILE="$(echo "$line" | cut -f2 | sed -e "s|~|$HOME|")" | |
| # Track directories with a symlink | |
| echo "$TARGET_FILE" >> $TRACKED_DOTFILES_FILE | |
| ln -sfv "$(realpath -s "$SOURCE_FILE")" "$TARGET_FILE" | |
| done | |
| # Dedup the cache file | |
| cat $TRACKED_DOTFILES_FILE | sort | uniq > "$TRACKED_DOTFILES_FILE.tmp" | |
| mv "$TRACKED_DOTFILES_FILE.tmp" "$TRACKED_DOTFILES_FILE" | |
| // Dictionary of escape sequences | |
| // TODO: Also add bold, underline, blick, ... | |
| const escapes = { | |
| reset: `\\033[0m`, | |
| colors: { | |
| black: `\\033[0;30m`, | |
| red: `\\033[0;31m`, | |
| green: `\\033[0;32m`, | |
| yellow: `\\033[0;33m`, | |
| blue: `\\033[0;34m`, | |
| purple: `\\033[0;35m`, | |
| cyan: `\\033[0;36m`, | |
| white: `\\033[0;37m`, | |
| intense_black: `\\033[0;90m`, | |
| intense_red: `\\033[0;91m`, | |
| intense_green: `\\033[0;92m`, | |
| intense_yellow: `\\033[0;93m`, | |
| intense_blue: `\\033[0;94m`, | |
| intense_purple: `\\033[0;95m`, | |
| intense_cyan: `\\033[0;96m`, | |
| intense_white: `\\033[0;97m`, | |
| }, | |
| backgrounds: { | |
| black: `\\033[40m`, | |
| red: `\\033[41m`, | |
| green: `\\033[42m`, | |
| yellow: `\\033[43m`, | |
| blue: `\\033[44m`, | |
| purple: `\\033[45m`, | |
| cyan: `\\033[46m`, | |
| white: `\\033[47m`, | |
| intense_black: `\\033[0;100m`, | |
| intense_red: `\\033[0;101m`, | |
| intense_green: `\\033[0;102m`, | |
| intense_yellow: `\\033[0;103m`, | |
| intense_blue: `\\033[0;104m`, | |
| intense_purple: `\\033[0;105m`, | |
| intense_cyan: `\\033[0;106m`, | |
| intense_white: `\\033[0;107m`, | |
| }, | |
| } | |
| // TODO: Add the remaining prompt variables | |
| const ps1_variables = { | |
| working_directory: '\\w', | |
| username: '\\u', | |
| host: '\\h', | |
| } | |
| const no_print_region = (body) => '\\[' + body + '\\]'; | |
| const style = (opts, ...body) => { | |
| let s = ''; | |
| body = join(...body); | |
| if (opts.color) | |
| s += no_print_region(escapes.colors[opts.color]); | |
| if (opts.background) | |
| s += no_print_region(escapes.backgrounds[opts.background]); | |
| s += body; | |
| s += no_print_region(escapes.reset); | |
| return s; | |
| } | |
| const command = (opts, ...body) => { | |
| let s = ''; | |
| body = join(...body); | |
| if (opts.escape) { | |
| // TODO: Add other escaped characters | |
| body = body.replace( /"/g, '\\"') | |
| .replace(/\$/g, '\\$'); | |
| } | |
| s += opts.escape ? '\\`' : '\`'; | |
| s += body; | |
| s += opts.escape ? '\\`' : '\`'; | |
| return s; | |
| } | |
| const variable = (name) => ps1_variables[name]; | |
| const join = (...body) => body.join(''); | |
| console.log( | |
| join( | |
| // show special symbol if previous command ended without newline | |
| command({ }, | |
| 'printf "', | |
| style({ color: 'white', background: 'black' }, '%%'), | |
| '%', | |
| command({ escape: true }, | |
| 'echo -e "$((COLUMNS-1))"' | |
| ), | |
| 's\\r"', | |
| ), | |
| // user & host information | |
| '[', | |
| style({ color: 'intense_purple' }, | |
| variable('username') | |
| ), | |
| '@', | |
| style({ color: 'green' }, | |
| variable('host') | |
| ), | |
| ']', | |
| // python virtualenv prompt | |
| command({}, | |
| '__virtualenv_ps1 " [', | |
| style({ color: 'blue' }, '%s'), | |
| ']"' | |
| ), | |
| // git prompt | |
| command({}, | |
| '__git_ps1 " [', | |
| style({ color: 'red' }, '%s'), | |
| ']"' | |
| ), | |
| // working directory on newline | |
| '\\n', | |
| ' ', | |
| style({ color: 'intense_black' }, | |
| variable('working_directory') | |
| ), | |
| ' $ ' | |
| ) | |
| ); | |
| #!/bin/bash | |
| # TARGET_FILE=~/.local/bin/xfce4_screenshot | |
| xfce4-screenshooter $* | |
| if [[ "$*" == *-c* && -n "$(find /tmp -name '*.png' -newermt '-1 seconds')" ]]; then | |
| notify-send -i image-x-generic "Screenshot" "Picture copied to clipboard" | |
| fi | |