Last active
May 1, 2023 19:21
-
-
Save aiventures/e3987f9d1a56f20ad7a945ed83cfdc3e to your computer and use it in GitHub Desktop.
Bash Snippets
This file contains 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
alias oi="open_extended ${f_info}" | |
alias ow="open_extended ${p_docs}/worklog.txt" | |
# frequently used git aliases | |
alias git_log="git log -p -3" | |
alias git_log_graph="git log -3 --stat --graph --pretty=format:\"%H - %an, %ar : %s\"" | |
# frequently used find commands | |
# get number of files of a given type and find filenames | |
alias find_filetype_stats="find . -type f | egrep -i -E -o \"\.{1}\w*$\" | sort | uniq -c" | |
alias find_filetype="echo \"find ./ -type f -regex '.*\.\(txt\|url\)$'|sort|grep .\"" | |
# recursively list directories | |
# ls -R -1 --color=always | |
# alias lsr="ls -1 -R -X" | |
alias lsr="ls -1 -R --color=always" | |
# search recursively for files | |
alias find_r="find . -print | grep --color=always -in" | |
# find in anleitungen folder | |
# find recursively in directories (files would be -f option) | |
alias find_dirs="find . -mindepth 1 -type d | grep -i --color=always" | |
# search in single files | |
alias s_python_snippets="cdd ${p_machine_learning_infos}; grep_single_file doc_python_snippets.txt" | |
alias s_total_commander="cdd ${p_docs}; grep_single_file doc_total_commander_local.txt" | |
alias s_python="cdd ${p_docs}; grep_single_file doc_python.txt" | |
alias s_tools="cdd ${p_docs}; grep_single_file doc_tools.txt" | |
# alias s_npp="cdd ${p_laufende_dokumente}/Anleitungen; grep_single_file NotepadPlusPlusShortcuts.txt" | |
# alias s_links="cdd ${p_laufende_dokumente}/Browserlinks; grep_single_file browserlinks.json" | |
# COLORMODE for todo lists: "X" is with rich colors, normal otherwise | |
# search in shortcut file | |
alias s_sh="cdd ${p_docs}; grep_single_file doc_shortcuts_local.txt" | |
alias s_npp="cdd ${p_docs}; grep_single_file doc_shortcuts_local.txt notepad++" | |
alias s_chrome="cdd ${p_docs}; grep_single_file doc_shortcuts_local.txt chrome" | |
alias s_edge="cdd ${p_docs}; grep_single_file doc_shortcuts_local.txt edge" | |
alias s_vscode="cdd ${p_docs}; grep_single_file doc_shortcuts_local.txt vscode" | |
alias s_mlo="cdd ${p_docs}; grep_single_file doc_shortcuts_local.txt mlo" | |
alias s_bash="cdd ${p_docs}; grep_single_file doc_shortcuts_local.txt bash" | |
alias s_cmder="cdd ${p_docs}; grep_single_file doc_shortcuts_local.txt cmder" | |
alias s_tc="cdd ${p_docs}; grep_single_file doc_shortcuts_local.txt totalcommander" | |
export COLOR_MODE="X" | |
function grep_single_file () { | |
: "usage grep_single_file filepath arg1 arg2 ... " | |
: "performs search in a single file for arg1 arg2 " | |
p=${1} | |
grep_cmd="grep -iHn --color=always \"@\" \"#\"" | |
# replace placeholders @ and # | |
grep_cmd="${grep_cmd//#/${p}}" | |
grep_cmd="${grep_cmd//@/${2}}" | |
grep_pipe="|grep --color=always -in" | |
args=("$@") | |
for ((i=2; i<$#; i++)) | |
do | |
grep_cmd+="${grep_pipe} ${args[i]}" | |
done | |
echo "${grep_cmd}" | |
eval "${grep_cmd}" | |
} | |
------------------------------- | |
https://learn.microsoft.com/de-de/windows/wsl/install | |
######## WINDOWS SYSTEMPATH | |
####### %TOOLS_PATH% | |
ComSpec %SystemRoot%\system32\cmd.exe <SYSTEM> | |
HOME C:\...\CMD\githome <SYSTEM> | |
P_DEVTOOLS %PY_HOME%;%PY_HOME%\Lib;%PY_HOME%\DLLs;%P_GIT%\bin;%P_GIT%\cmd | |
P_GIT C:\...\git-for-windows | |
P_NPP %...%\Notepad++ | |
P_PY_MYLIBS C:\...\root | |
P_PY_MYTOOLS %P_PY_MYLIBS%\tools <SYSTEM> | |
P_TOOLS C:\10_Tools | |
Path %SystemRoot%;%SystemRoot%\system32;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%SYSTEMROOT%\System32\OpenSSH\;%P_DEVTOOLS%;C:\Progra~2\NVIDIA~1\PhysX\Common;C:\Progra~1\NVIDIA~1\NVIDIA~3;;C:\30_Entwicklung\VSCode\bin <SYSTEM> | |
Path %USERPROFILE%\AppData\Local\Microsoft\WindowsApps; NT-AUTORITÄT\SYSTEM | |
Path %USERPROFILE%\AppData\Local\Microsoft\WindowsApps;%TOOLS_PATH%; | |
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC | |
PY_HOME C:\<>\Python <SYSTEM> | |
PYTHONPATH C:\<...>\WORK_JUPYTER\root <SYSTEM> | |
TMP %SystemRoot%\TEMP <SYSTEM> | |
TOOLS_PATH C:\<...>; | |
# .bashrc | |
# echo "---- $HOME/.bashrc ----" | |
# For windows: set Windows env variable HOME to | |
# directory containing .bashrc | |
# this folder is entry point for shell/git | |
# if you have bashrc already, add the util | |
# load util functions and global definitions | |
# . ~/util.sh | |
# bashrc | |
############## | |
echo "---- BEGIN shortcuts_personal.sh ----" | |
# open frequently used links links | |
alias go_github="open \"https://github.com/aiventures\"" | |
# go to directory | |
#################### | |
### additional stuff | |
#alias lc_desktop="lc ${p_desktop}" | |
#alias cdd_desktop="cdd ${p_desktop}; lc" | |
#alias open_desktop="open \"${p_desktop}\"" | |
# convenience aliases for some bash commands | |
# ls only directories | |
alias ls_dir="ls -d */*/ -1" | |
# activate environment | |
# TODO create VENV | |
alias py_activate22='cd "${p_entwicklung}/VENV/.../Scripts"; . activate' | |
alias py_deactivate22='cd "${p_entwicklung}/VENV/.../Scripts"; deactivate' | |
# move current directory to processed folder | |
function move_shared_picture () { | |
p_move="$(pwd)" | |
echo "${p_move}" | |
cd ".." | |
mv -v "${p_move}" "${p_folder}" | |
} | |
# create metadata.tpl, copy control files, validate files | |
alias img_file_validator="python \"${p_tools_cmd}/xxx.py\"; open ." | |
# display information about img_... aliases | |
function help () { | |
# cdd "${p_photos_umo}" | |
echo "Aliases for img_..." | |
grep_alias img_ | |
echo "(0) PREPARE" | |
} | |
alias help_img="help" | |
# frequently used git aliases | |
alias git_log="git log -p -3" | |
alias git_log_graph="git log -3 --stat --graph --pretty=format:\"%H - %an, %ar : %s\"" | |
# frequently used find commands | |
# get number of files of a given type and find filenames | |
alias find_filetype_stats="find . -type f | egrep -i -E -o \"\.{1}\w*$\" | sort | uniq -c" | |
alias find_filetype="echo \"find ./ -type f -regex '.*\.\(txt\|url\)$'|sort|grep .\"" | |
# recursively list directories | |
# ls -R -1 --color=always | |
# alias lsr="ls -1 -R -X" | |
alias lsr="ls -1 -R --color=always" | |
# search recursively for files | |
alias find_r="find . -print | grep --color=always -in" | |
# find in folder | |
alias find_anleitungen='cdd "${p_laufende_dokumente}/some_folder"; find . -print | grep --color=always -in' | |
# find recursively in directories (files would be -f option) | |
alias find_dirs="find . -mindepth 1 -type d | grep -i --color=always" | |
# COLORMODE for todo lists: "X" is with rich colors, normal otherwise | |
export COLOR_MODE="X" | |
# activate python environment | |
py_activate22 | |
# display current python environment | |
alias py_env='echo PY ENV: "$VIRTUAL_ENV"' | |
# https://stackoverflow.com/questions/4133904/ps1-line-with-git-current-branch-and-colors | |
# show venv https://gist.github.com/miki725/9783474 | |
function color_my_prompt { | |
# local __py_env="[\$VIRTUAL_ENV]" | |
local __lambda=$'\u03bb' | |
local __user_and_host="\[\033[01;32m\]\u@\h" | |
local __cur_location="\[\033[01;34m\]\w" | |
local __git_branch_color="\[\033[31m\]" | |
#local __git_branch="\`ruby -e \"print (%x{git branch 2> /dev/null}.grep(/^\*/).first || '').gsub(/^\* (.+)$/, '(\1) ')\"\`" | |
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`' | |
local __prompt_tail="\[\033[35m\]" | |
local __symbol="$__lambda" | |
local __last_color="\[\033[00m\]" | |
local __venv="" | |
if ! test -z "$VIRTUAL_ENV" ; then | |
#__venv="${BLUE}[`basename \"$VIRTUAL_ENV\"`]${COLOR_NONE} " | |
__venv=" [`basename \"$VIRTUAL_ENV\"`] " | |
fi | |
export PS1="$__user_and_host $__cur_location$__git_branch_color $__git_branch$__venv\n$__prompt_tail$__symbol$__last_color " | |
} | |
# export PS1="\\w:\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\$ " | |
# wont display branch if not got controlled | |
color_my_prompt | |
alias prompt_default='export PS1="\[\033[01;32m\]\u@\h \[\033[01;34m\]\w \[\033[31m\]`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`\n\[\033[35m\]λ\[\033[00m\]"' | |
# $'\u03bb'' \[\033[0m\]' | |
############################################## | |
BASH Shortcuts and function to display shortcuts | |
### BASH SHORTCUTS | |
VIM (vim) :help in editor press ESC, :q! | |
### CHAR/WORD CORRECTIONS | |
[CHAR] CTRL + t [cA_Bd > cBA_d] Tauschen/swap CHAR before/after cursor | |
[WORD] ALT + t [ABC_XYZ > XYZ ABC_] Tauschen/swap WORD before/after cursor: | |
[CHAR] CTRL + h [c#_bd > c_bd] Delete CHAR before Cursor | |
[CHAR] CTRL + d [ca_#d > ca_d] Delete CHAR after Cursor | |
[WORD] ALT + d [abc_### > abc_] Delete WORD after Cursor | |
[WORD] ALT + u [abc_xyz > abcXYZ_] Upper case WORD | |
[WORD] ALT + l [abc_XYZ > abcxyz_] Lower case WORD | |
[CHAR] ALT + c [xa_by > xaBy_] Capitalize CHAR after Cursor/move to next word | |
[WORD] CTRL + w [###_xyz > xyz] Cut WORD before cursor to clipboard | |
[LINE] CTRL + k [123_### ### > 123_] Cut LINE after cursor to clipboard | |
[LINE] CTRL + u [###_abc xyz > _abc xyz]Cut LINE before cursor to clipboard | |
### NAVIGATION | |
CTRl + a (anfang) - HOME | |
CTRL + e (ende) - END | |
ALT + b (backwards one word) | |
ALT + f (forward one word) | |
### EDITING | |
TAB Tab completion for file/directory names | |
history #n Show last #n entries from history | |
CTRL + R History search, type string, go back with CTRL+R | |
![NUM] Enter the NUM form history to execute command | |
ALT + r (revert changes like history) | |
CTRL + L clear Screen | |
CTRL + p (previous COMMAND) | |
CTRL + n (next COMMAND) | |
CTRL + y paste last cut | |
CTRL + _ Undo (CTRL + SHIFT + -) | |
CTRL + +/- Change Font Size | |
# SOME BASH VARIABLE OF INTEREST | |
# History Values | |
# HISTFILE,HISTSIZE,HISTFILESIZE | |
# ALIASES FOR WORK | |
# search in folder alias grep_m='ls -a; grepm"grep --color=always -irn"' | |
# move to a folder, search in filename with mutliple keywords alias find_folder='cdd"${FOLDER}"; find . -print | grep --color=always -in' | |
# find directories recursively by directory name with keywords alias find_dirs='find . -mindepth 1 -type d | grep -i --color=always' | |
# file statistics alias find_filetype_stats='find . -type f | egrep -i -E -o"\.{1}\w*$" | sort | uniq -c' | |
# search for file names alias find_r='find . -print | grep --color=always -in' | |
# Bash Command aliases | |
# alias git_config='git config --list --global &' | |
# alias git_difftool='git difftool --dir-diff &' | |
# alias git_mergetool='git mergetool &' | |
# search in available aliases alias grep_alias='grepm"alias"' | |
# search in all functions / executables alias grep_commands='grepm"compgen -abckA function"' | |
# display all functions alias grep_functions='grepm"declare -F|grep -iv _git"' | |
# search in enviroment variables alias grep_env='grepm"env"' | |
# display exported variables alias grep_export='grepm"export -p"' | |
# display all declared variables alias grep_variables='grepm"compgen -v"' | |
# search in a single file alias greps_doc_sf="cdd \"$p\":single_file; grep_single_file \"$single_file\"" | |
# display a function definition type <func_name> [| grep --color=always -in":"] / with or without full code | |
function bash_shortcuts_info () { | |
: bash shortcuts help | |
echo "### BASH SHORTCUTS" | |
echo "" | |
echo "VIM (vim) :help in editor press ESC, :q!" | |
echo "" | |
echo "### CHAR/WORD CORRECTIONS" | |
echo " [CHAR] CTRL + t [cA_Bd > cBA_d] Tauschen/swap CHAR before/after cursor" | |
echo " [WORD] ALT + t [ABC_XYZ > XYZ ABC_] Tauschen/swap WORD before/after cursor:" | |
echo " [CHAR] CTRL + h [c#_bd > c_bd] Delete CHAR before Cursor" | |
echo " [CHAR] CTRL + d [ca_#d > ca_d] Delete CHAR after Cursor" | |
echo " [WORD] ALT + d [abc_### > abc_] Delete WORD after Cursor" | |
echo " [WORD] ALT + u [abc_xyz > abcXYZ_] Upper case WORD" | |
echo " [WORD] ALT + l [abc_XYZ > abcxyz_] Lower case WORD" | |
echo " [CHAR] ALT + c [xa_by > xaBy_] Capitalize CHAR after Cursor/move to next word" | |
echo " [WORD] CTRL + w [###_xyz > xyz] Cut WORD before cursor to clipboard" | |
echo " [LINE] CTRL + k [123_### ### > 123_] Cut LINE after cursor to clipboard" | |
echo " [LINE] CTRL + u [###_abc xyz > _abc xyz] Cut LINE before cursor to clipboard" | |
echo "### NAVIGATION" | |
echo " CTRl + a (anfang) - HOME" | |
echo " CTRL + e (ende) - END" | |
echo " ALT + b (backwards one word)" | |
echo " ALT + f (forward one word)" | |
echo "### EDITING" | |
echo " TAB Tab completion for file/directory names" | |
echo " history #n Show last #n entries from history" | |
echo " CTRL + R History search, type string, go back with CTRL+R" | |
echo " ![NUM] Enter the NUM form history to execute command" | |
echo " ALT + r (revert changes like history)" | |
echo " CTRL + L clear Screen" | |
echo " CTRL + p (previous COMMAND)" | |
echo " CTRL + n (next COMMAND)" | |
echo " CTRL + y paste last cut" | |
echo " CTRL + _ Undo (CTRL + SHIFT + -)" | |
echo " CTRL + +/- Change Font Size" | |
} | |
alias help_bash="bash_shortcuts_info" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment