-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaliases.sh
95 lines (84 loc) · 2.53 KB
/
aliases.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -------------------------------------------------------
# Original Author: Nathan Broadbent
# Modified By: Michael-Keith Bernard
# Source: https://github.com/ndbroadbent/ubuntu_config
# Retrieved: Oct 19, 2011
# -------------------------------------------------------
# -------------------------------------------------------
# Aliases, functions & key bindings
# -------------------------------------------------------
# -- shortcuts
alias serve="python -m 'SimpleHTTPServer'"
# -- bash
alias l='ls -Cv --group-directories-first'
alias ll='ls -lv --group-directories-first'
alias la='ls -lvA --group-directories-first'
alias _='sudo'
alias n='nautilus .'
alias tmux="tmux -2"
alias ~='cd ~'
alias cl='cd -'
alias ..='cd ..'
alias ...='cd ../..';
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
# -- apt
alias apt-install='sudo apt-get install -y'
alias apt-search='apt-cache search'
# -------------------------------------------------
# Include configurable bash aliases, if file exists
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# ---------------------------------------------------------
# Alias management (helper functions for ~/.bash_aliases)
# ---------------------------------------------------------
# Adds a directory, then cds into it
# ------------------------------------------------
function mkd() {
if [ -n "$1" ]; then
mkdir -p $1
cd $1
else
echo "Usage: mkd <directory_name>"
fi
}
# Adds an alias to ~/.bash_aliases.
# ------------------------------------------------
function add_alias() {
if [ -n "$1" ] && [ -n "$2" ]; then
touch ~/.bash_aliases
echo "alias $1=\"$2\"" >> ~/.bash_aliases
source ~/.bashrc
else
echo "Usage: add_alias <alias> <command>"
fi
}
# Adds a change directory alias to ~/.bash_aliases.
# Use '.' for current working directory.
# Changes directory, then lists directory contents.
# ------------------------------------------------
function add_dir_alias() {
if [ -n "$1" ] && [ -n "$2" ]; then
path=`dirname $2/.` # Fetches absolute path.
touch ~/.bash_aliases
echo "alias $1=\"cd $path; ll\"" >> ~/.bash_aliases
source ~/.bashrc
else
echo "Usage: add_dir_alias <alias> <path>"
fi
}
# Remove an alias
# ------------------------------------------------
function rm_alias() {
if [ -n "$1" ]; then
touch ~/.bash_aliases
grep -Ev "alias $1=" ~/.bash_aliases > ~/.bash_aliases.tmp
mv ~/.bash_aliases.tmp ~/.bash_aliases
unalias $1
source ~/.bashrc
else
echo "Usage: rm_alias <alias>"
fi
}