Skip to content

Instantly share code, notes, and snippets.

@Sebiee
Sebiee / .bashrc
Created January 29, 2026 09:23
Useful automatic cmds when cd-ing
cd() {
builtin cd "$@" || return
(
set +m;
if [ -d '.git' ]; then
o=$(git fetch origin 2>&1) &&
[ -n "$o" ] && printf '\e[1A\e[2K\e[1A\e[2K' &&
echo -e "$o" &&
echo -e "\033[01;32m\n@@@@@@@@" &&
echo -e "@ There were changes since last time you were here. Please merge\!" &&
@Sebiee
Sebiee / gist:af9b8f1a11eaa3e7a6da837ce7adeae6
Created March 28, 2024 12:22
Bash overwrite file in place, without creating a temporary one
myfile=test.txt &&
# Identify the starting and ending line of the block you want to replace
replace_this_start=$(grep -n 'STARTLINE_OF_STRING_THAT_NEEDS_REPLACEMENT' \
${myfile} | awk -F':' '{ print $1 }') &&
replace_this_stop=$(grep -n 'ENDLINE_OF_STRING_THAT_NEEDS_REPLACEMENTt' \
${myfile} | awk -F':' '{ print $1 }') &&
(
head -n${replace_this_start} ${myfile} &&