• Stars
    star
    181
  • Rank 207,811 (Top 5 %)
  • Language
    Python
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🚀 Collection of bash snippets/aliases that will save your time on the terminal

awesome-bashrc


🚀 Curated list of awesome bashrc snippets that will make your work easier.

Inspiration

Working with bash in daily life, it is very irritating writing the same command multiple times. To avoid that we write aliases/snippets for bashrc and make our life easier.

This repository will have collection of such aliases. Read Contribution Guidelines before contributing.

Contents

C/C++ compile and run

cpp-run() {
    echo "Compiling file..."
    g++ -o "$1" "$1.cpp"
    echo "Compiled! Enter input :D"
    ./"$1"
}
# cpp-run filename

c-run() {
    echo "Compiling file..."
    gcc -o "$1" "$1.c"
    echo "Compiled! Enter input :D"
    ./"$1"
}
# c-run filename

git diff for JS Devs

alias gd="git diff --ignore-all-space 
                    --ignore-space-at-eol 
                    --ignore-space-change 
                    --ignore-blank-lines -- . 
                    ':(exclude)*package-lock.json'"

# Write gd to ignore not important differences.
# Credits: https://www.reddit.com/r/javascript/comments/9i6hl3/alias_for_open_source_js_devs/

git status

alias s="git status"

Upload your package to PyPi.org

This generates the respective dist files and uploads them to PyPi.org by asking your credentials at the end.

alias pyup="python setup.py sdist bdist_wheel && twine upload dist/*"

apt-get update

alias update='sudo apt-get update'

open

Open any file using its default program (eg. pdfs, torrents, etc).

alias open="xdg-open"

List files

alias ll='ls -laht'
alias l='ls -aC'

Tally

tally() {
  if [[ $1 == '--help' ]]; then
    echo "Usage: ls | tally";
    return 0;
  fi
  
  sort | uniq -c | sort -n
}

Check free space on disks

alias df='df -h'

Safe operations with files

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

git branch

This will display the current git branch of any repository you're in.

# Add git branch if its present to PS1
parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

# Pass the function to the color parser of the terminal to colorize the branch name.
if [ "$color_prompt" = yes ]; then
    if [[ ${EUID} == 0 ]] ; then
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\h\[\033[01;34m\] \W $(parse_git_branch)\$\[\033[00m\] '
    else
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w $(parse_git_branch)\$\[\033[00m\] '
    fi
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h \w \$ '
fi
unset color_prompt force_color_prompt

git.io alias

Get shortened git.io URLs from a single command

gurl() {
    curl -i https://git.io -F "url=$1" \
    -F "code=$2"
}

# Usage
# gurl https://github.com/anshumanv anshumanv

After these steps, https://git.io/anshumanv will redirect you to https://github.com/anshumanv

tree alias

Get representation of underlying files and folders as a tree.

alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"

Fast upwards navigation (comes with ZSH)

alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'

Download music from youtube video

You will need mp3-lame library and youtube-dl utility.

alias youtube-mp3="youtube-dl --extract-audio --audio-format mp3"
# Usage
# youtube-mp3 https://youtube.com/{id}

Get saved WiFi keys

alias wifikey="sudo grep -r '^psk=' /etc/NetworkManager/system-connections/"
# Usage (requires sudo)
# wifikey

Take Screenshot of connected ADB Device

alias cap="adb shell screencap -p /sdcard/screen.png && \
           adb pull /sdcard/screen.png && \
           adb shell rm /sdcard/screen.png"
# Usage (requires connected device)
# Saves the screenshot with name screen.png
# cap

Bootstrap your CF Round

cf() {
    mkdir "CF#$1" &&\
    cd "CF#$1" &&\
    touch inp.txt &&\
    touch out.txt && \
    curl -L "https://files.aashutosh.dev/cpp.cpp" -o A.cpp
}

# Usage: cf 549
# The above command initialzes, Your CF Round folder and downloads your sample template.
# https://files.aashutosh.dev/cpp.cpp refers to link of your template

Run Matlab scripts

matlab-run() {
    matlab -nodesktop -nosplash -r "$1"
}
# matlab-run filename

Convert GIF to WebM

Why? => Read this (You can save upto 90% on size of media)

gif2webm() {
    ffmpeg -i $1.gif -c vp9 -b:v 0 -crf 41 $1.webm
}
# gif2webm gif-name-without-format

Python

Framework used for coming up with aliases for Python:

  • To create / make a directory, mkdir is used and to remove a directory rmdir is used. Extending this logic of using mk and rm for aliases.

For example:

  1. pirm : pip remove a package
  2. mkvenv : To create / make a virtual environment

First defining a custom print function to pretty print alias output. This will help us distinguish between command output and alias output

function repeat {
    num="${2:-100}"; printf -- "$1%.0s" $(seq 1 $num);
}

# custom print function for pretty printing aliases/ functions
function print {
    terminalCols=$(tput cols)
    argLen=${#1}
    offset=$(((terminalCols-argLen)/2))

    printf "\n"
    repeat '#' $((offset-1))
    printf " $1 "
    repeat '#' $((offset-1))
    printf "\n"     
}

NOTE: If you are not interested in using these helper functions, you can replace print with echo in all the below code snippets.

Aliases specific to python:
alias 'py'='python'
alias 'pirm'='pip uninstall -y'
alias 'sdist'='rm -rf dist/ ; py setup.py sdist'
alias 'bdist'='rm -rf dist/ ; py setup.py bdist_wheel'

# Pip install 
function pi {
    if [ -z "$1" ]
    then 
        # Looks for setup.py in the current directory and installs the package
        print "Installing from local setup.py file in the current directory"
        pip install .
    else 
        # Installs the package from PyPI 
        print "Fetching from PyPI"
        pip install "$1"
    fi
}

alias 'pii'='pi'
Python virtual environments
To create a python virtual environment in the current directory:
# Create new venv using python3
# If no name is passed will default to .venv
function mkvenv {
    if [ -z "$1" ]
    then
        print "Creating virtualenv: .venv"
        python3 -m venv .venv
        avenv
    else
        print "Creating virtualenv: $1"
        python3 -m venv "$1"
        avenv "$1"
    fi

    print "Upgrading pip"
    pip install pip --upgrade

    print "Installing wheel package"
    pip install wheel
    print "Activated virtualenv"
}

alias 'mkenv'='mkvenv'
To remove a python virtual environment in the current directory
# Remove a virtual env.
# If no name is passed will default to .venv
function rmvenv {
    if [ -z "$1" ]
    then
        print "Removing virtualenv: .venv"
        python3 -m venv .venv
        rm -rf .venv
    else
        print "Removing virtualenv: $1"
        rm -rf "$1"
    fi
}

alias 'rmenv'='rmvenv'
To activate a virtual environment in the current directory.

Going by the general assumption that python virtual environments are named as:

  • .venv : Local virtual environemnt
  • .venv37 : Local virtual environment with Python 3.7
  • .venv38 : Local virtual environment with Python 3.8

The below alias uses fzf to choose a virtual environment to activate when there are multiple virtual environments in the current directory.

# Activate virtual env
# If no name is passed will default to .venv
function avenv {
    # If no paramerter is passed try to activate .venv first. If .venv doesnt exist try with the next closest one. If both .venv37 and .venv38 exist. It will pick .venv37
    # If parameter is passed, try to activate that one
    if [ -z "$1" ]
    then

        if [ -d ".venv" ] 
        then
            source .venv/bin/activate 
            print "Activated virtualenv: .venv" 

        else   
            # Piping the output of find command to fzf to select a virtual env.
            virtual_env=$(find -maxdepth 2  -type d -name ".venv*"  | fzf)  
            print "Activated virtualenv: $virtual_env" 
            source "$virtual_env"/bin/activate
        fi 

    else
         source "$1"/bin/activate; print "Activated virtualenv: $1" || print "Failed to activate virtualenv: $1"

    fi
}

alias 'aenv'='avenv'
To deactivate a virtual environment
# Deactivate virtual env

function dvenv {

    if [ -z "$1" ]
    then
        deactivate || print "Failed to deactivate virtualenv: .venv"
        print "Deactivated virtualenv"
    else
        deactivate "$1" || print "Failed to deactivate virtualenv: $1"
        print "Deactivated virtualenv" 
    fi
}
alias 'denv'='dvenv'
Anaconda Python

Utilizes the mamba executable wherever possible to improve anaconda command execution times.

Follows a similar style of aliases as the above set of python aliases.

Only difference is, aliases are prefixed with c.

#  MAMBA: Currently, only install, create, list, search, run, info and clean are supported through mamba.

#list envs
alias 'clsenv'='mamba env list'
alias 'clsvenv'='clsenv'
To create a conda environment
#create new venv
function cmkvenv {
   mkdir -p /usr/softwares/miniconda3/envs/"$1"
#  mamba create -n "$1" --prefix=/usr/softwares/miniconda3/envs/"$1" python="$2" -y
  conda create  --prefix=/usr/softwares/miniconda3/envs/"$1" python="$2" -y
}
alias 'cmkenv'='cmkvenv'
To remove a conda environment
# remove arbitrary number of conda virtual envs
function crmenv {
  mamba env remove -n "$@"
}

alias 'crmvenv'='crmenv'
To activate/ deactivate a conda environment
#activate venv.
#Can't use mamba for activation and deactivation of env
function caenv {
  conda activate "$1"
}

#deactivate venv
alias "cdvenv"="conda deactivate"
alias "cdenv"="cdvenv"
To add/remove and list conda channel(s)
#add channels in conda
function caddc {
    if [ -z "$1" ]
    then
        echo "Provide a channel name to add!"
        #exit 1;
    else
        mamba config --add channels "$1"
    fi
}

#list channels in conda
function clsch {
  conda config --show channels
}

# remove a channel
function crmch {
    conda config --remove channels "$1"
}
To install / remove a conda package
#Conda install a package
function ci {
    if [ -z "$2" ]
    then
        /usr/softwares/miniconda3/condabin/mamba install -y "$1"
    else
         /usr/softwares/miniconda3/condabin/mamba install -c "$2" "$1"
    fi
}

#Conda remove a package
alias 'crm'='mamba uninstall -y'

License

CC0


File Templates taken from awesome-no-login-web-apps

Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY

More Repositories

1

Testcase-Generator

⚡️ Handy script for HackerRank, HackerEarth and CodeChef TCs Generation.
Python
101
star
2

Insta-Downloader-Extension

A browser extension that injects download buttons ⬇️ for media on Instagram Web
JavaScript
74
star
3

py-scripts

These are daily life scripts for windows users to make their day easy.
Python
63
star
4

git-stalk-cli

A CLI tool for keeping an eye on contributions of peers (Python Package)
Python
43
star
5

GitHub-Dash-Aligner

New update of GitHub moved Dashboard to Left-Hand side, switch back with just one click.
JavaScript
31
star
6

vision

TensorFlow Image Classifier + TTS for small devices
Python
28
star
7

git-profiler-bot

Telegram bot which fetches GitHub Profiles.
Python
24
star
8

labper

Smart Lab Management System (built using Django)
CSS
22
star
9

1Chat

Flutter and FireStore based Chat App
Dart
19
star
10

auto-openvpn

A cli tool for generating OpenVPN account, which can be used for 5 days. (Python Package)
Python
16
star
11

dcart

Ξ Decentralized Online Market Prototype
JavaScript
15
star
12

keepr

Yet Another Note Keeper
Dart
12
star
13

SpringCRUD

Basic CRUD with SpringBoot + Hibernate
Java
9
star
14

aashutoshrathi

Hey 👋🏻
9
star
15

Student-Lifecycle-Management

Student Portal for Colleges
HTML
9
star
16

oc-frontend

OC Frontend Diploma
JavaScript
6
star
17

downasaur-bot

AI Powered Bot for auto playing India's most accessible game.
Jupyter Notebook
6
star
18

medtour

A Medical Tourism Implementation
CSS
6
star
19

scheduling-algorithms

A basic Python implementation of FCFS, SJF and Round Robin
Python
6
star
20

Elf

Linux Terminal interpreter in C
C
5
star
21

Jira-Todo

A simple menu bar app that gives you quick access to your Todos on Jira
Python
5
star
22

mongo-ip-updater

A simple script which upserts your IP in Mongo NAL
HTML
5
star
23

Typeracer

Clone of Typeracer as Computer Network Project
JavaScript
5
star
24

dustbin-locator

Firebase and Google Maps powered asset locator dashboard
JavaScript
4
star
25

competitive-programming

Collection of my CP Codes (few but not null)
C++
4
star
26

django-filter-product

Django Project Sample for filtering product like Amazon
CSS
4
star
27

aashutosh.dev

~/aashutosh
JavaScript
3
star
28

One-Cheque-Salary-for-Small-Business

Time saving ⏰ C script for small businesses, who pay to employees by cheque
C
2
star
29

api-screenshot

JavaScript
2
star
30

gantavya

A simple edge function to return the final destination of a url
TypeScript
2
star
31

is-doing-x.user.domain

HTML page to show yes to questions like isSleeping, isCovidPositive, isDrinkingTea using sheetDB
JavaScript
2
star
32

backup-blog.aashutosh.dev

blog-files
2
star
33

Basic-School-Management-System

This is a C implementation of a basic school management
C
1
star
34

1px

Go
1
star
35

status-on-the-edge

A simple edge function to return a status code you give in param
CSS
1
star