From 671131407e5b0ead3046fe730287d41fb078f0a8 Mon Sep 17 00:00:00 2001 From: Stefan Friese Date: Wed, 26 Jul 2023 17:10:15 +0200 Subject: [PATCH] added some functions and aliases --- bash/.bash_aliases | 9 ++++++ bash/.bash_functions | 77 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/bash/.bash_aliases b/bash/.bash_aliases index b635fb2..69182b2 100644 --- a/bash/.bash_aliases +++ b/bash/.bash_aliases @@ -2,3 +2,12 @@ alias ll='ls -alF' alias la='ls -A' alias l='ls -CF' + +# git aliases + +alias gs='git status' +alias ga='git add' +alias gc='git commit' +alias gp='git push' +alias gl='git log' + diff --git a/bash/.bash_functions b/bash/.bash_functions index 61f3463..69b40a4 100644 --- a/bash/.bash_functions +++ b/bash/.bash_functions @@ -7,3 +7,80 @@ ssh() { command ssh "$@" exit } + +# Creates a new directory and immediately changes into it +mkcd() { + mkdir -p "$1" && cd "$1" +} + +# Extract compressed files easily +extract() { + if [ -f "$1" ] ; then + case "$1" in + *.tar.bz2) tar xvjf "$1" ;; + *.tar.gz) tar xvzf "$1" ;; + *.tar.xz) tar Jxvf "$1" ;; + *.bz2) bunzip2 "$1" ;; + *.rar) unrar x "$1" ;; + *.gz) gunzip "$1" ;; + *.tar) tar xvf "$1" ;; + *.tbz2) tar xvjf "$1" ;; + *.tgz) tar xvzf "$1" ;; + *.zip) unzip "$1" ;; + *.Z) uncompress "$1" ;; + *.7z) 7z x "$1" ;; + *) echo "'$1' cannot be extracted via extract()" ;; + esac + else + echo "'$1' is not a valid file" + fi +} + +# Show your current public IP address to the clipboard +showip() { + curl -s http://ifconfig.me ; echo "" #| tr -d '\n' | pbcopy + # echo "Public IP Address copied to clipboard!" +} + +# Get the weather forecast for a given location. +weather() { + if [ -n "$1" ]; then + curl wttr.in/"$1" + else + curl wttr.in + fi +} + +# Fetch common .gitignore templates and append them to the current .gitignore file +gitignore() { + curl -sL "https://www.gitignore.io/api/$1" >> .gitignore +} + +# A quick way to search for a file in the current directory. +qfind() { + find . -name "$1" +} + +# Go up a specified number of directories (or one level if no argument provided) +up() { + local p="" + for ((i=1; i<=$1; i++)); do + p="../$p" + done + cd "$p" || return +} + +# Get the current timestamp (useful for creating timestamped files) +timestamp() { + date +%Y-%m-%d_%H-%M-%S +} + +# Create a backup of a file or directory with a timestamp appended to its name +backup() { + cp -r "$1" "$1_$(timestamp)" +} + +# URL-encode a given string (useful for creating encoded URLs in scripts) +urlencode() { + echo -n "$1" | xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g' +}