Just some useful terminal commands I’ve made over time#
Maybe they can help someone else?
mkcd#
How often do you do this?
1
2
|
mkdir <folder_name>
cd <folder_name>
|
Usage
Why don’t we make it just a little bit easier?
1
2
3
4
5
|
function mkcd() {
readonly folder=${1:?You must provide a directory name}
mkdir -p "${folder}"
cd "${folder}"
}
|
to (and more)#
I create a lot of files from the terminal, but then use an IDE for code editing (I know, I’ll learn Vim eventually). So I’ve made a bunch of related functions that make this a bit easier:
to: “touch open”#
1
2
3
4
|
function to() {
touch "$1"
code "$1"
}
|
Usage
toe: “touch open make executable”#
1
2
3
4
5
|
function toe() {
touch "$1"
code "$1"
chmod +x "$1"
}
|
toes: “touch open make executable and add a shebang to the top”#
1
2
3
4
5
6
|
function toes() {
touch "$1"
echo "#!/bin/zsh" > "$1"
chmod +x "$1"
code "$1"
}
|
git helpers#
Just little things to make git a bit easier
gac#
I often find myself adding everything and committing, so just make it one action.
1
2
3
4
5
6
7
8
9
10
11
|
function gac() {
echo
echo "Adding"
git add .
echo "Committing"
git commit -m "$@"
echo
echo "\t \033[1;32m✓\033[0m Added and committed, ready to push"
echo "\t \033[0;90m(You can commit and push safely using ´gacp´)\033[0m"
echo
}
|
Usage
gacp#
When I’m feeling bold, I extend this by pushing after the adding and committing. It does first ask you if you want to proceed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
function gacp() {
echo
echo "Adding"
git add .
echo "Committing"
git commit -m "$@"
echo
print -n "\t\033[35mPush to GitHub? [Y/n]:\033[0m "
read choice
if [[ -z "$choice" || "$choice" =~ ^[Yy]$ ]]; then
git push
echo
echo "\t \033[1;32m✓\033[0m Pushed to GitHub"
echo
else
echo
echo "Exiting..."
echo
fi
}
|
Usage