Bash Cheats selfless sharing

To improve the efficiency of those things you often forget the other by aliases and shortcuts. In this article, I shared these assistants of my favorite command , for I often forget things, they are very useful, I hope this can help you, as well as solve some frequent headaches for you.

If you use a computer all day, if you can find the need to repeat the command and note them for later use easily it would be great. They all stay there, hidden in ~ / .bashrc (or zsh user's ~ / .zshrc in), waiting to improve your life!

Bin Zhiyi Sheng

When I perform a command takes a long time to run, I often use multitasking, and then we must go back to check whether the operation has been completed. However, the usefulness of say command, now no longer the case (which is on MacOS; change to an equivalent manner according to your local environment):

function looooooooong {
START=$(date +%s.%N)
$*
EXIT_CODE=$?
END=$(date +%s.%N)
DIFF=$(echo "$END - $START" | bc)
RES=$(python -c "diff = $DIFF; min = int(diff / 60); print('%s min' % min)")
result="$1 completed in $RES, exit code $EXIT_CODE."
echo -e "\n⏰ $result"
( say -r 250 $result 2>&1 > /dev/null & )
}

This command will record the start and end times of the command, calculate the required number of minutes, and "say" command to the call, time spent and exit code. When a simple console ring tones can not use, I found this super useful.

Installation assistant

I started in childhood Ubuntu, and the first thing I need to learn is how to install the package. First of all I have to add one alias is its assistant (based on today's popular terrier named):

alias canhas="sudo apt-get install -y"

GPG signature

Sometimes I have to sign GPG signature to e-mail without the GPG extension or application, I will jump to the command line and use the following annoying Alias:

alias gibson="gpg --encrypt --sign --armor"
alias ungibson="gpg --decrypt"

Docker

Docker many sub-command, but Docker compose more. I've used these aliases to the  --rm flag thrown behind, but now no longer use these useful alias:

alias dc="docker-compose"
alias dcr="docker-compose run --rm"
alias dcb="docker-compose run --rm --build"

Google Cloud of gcurl assistant

For me, Google Cloud is a relatively new thing, but it has very many documents. gcurl is an alias to ensure that when connecting to Google Cloud API with local curl command with the authentication header, you can get all the correct header.

Git and ~ / .gitignore

I work a lot with Git, so I have a special part to introduce Git assistant.

One of my most useful assistant I used to clone GitHub repository. You do not have to run:

git clone [email protected]:org/repo /Users/glasnt/git/org/repo

I set up a clone function:

clone(){
    echo Cloning $1 to ~/git/$1
    cd ~/git
    git clone [email protected]:$1 $1
    cd $1
}

Even if every time you enter ~ / .bashrc file to see this, I always forget and giggle, I also have a "refresh upstream" command:

alias yoink="git checkout master && git fetch upstream master && git merge upstream/master"

Another aide to Git family is the global ignore file. In your git config --global --list, you should see a core.excludesfile. If not, create one, then you will always put the contents of each file .gitignore fill it. As Python developers on MacOS, for me, these elements are:

.DS_Store     # macOS clutter
venv/         # I never want to commit my virtualenv
*.egg-info/*  # ... nor any locally compiled packages
__pycache__   # ... or source
*.swp         # ... nor any files open in vim

You can find other suggestions on Gitignore.io or Gitignore repository on GitHub.

This article addresses: https://www.linuxprobe.com/bash-commands.html

Published 142 original articles · won praise 110 · views 370 000 +

Guess you like

Origin blog.csdn.net/u014389734/article/details/104231311