-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_aliases
75 lines (67 loc) · 2.36 KB
/
dot_aliases
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
#/usr/bin/bash
# Set vim to nvim if nvim exists on the system
command -v nvim > /dev/null && {
alias vim='nvim'
}
command -v lvim > /dev/null && {
alias vim='lvim'
}
alias 'du.'='du -hsx * | sort -rh | head -10'
alias 'dua'='du -hax -d0 .[!.]* * | sort -rh | head -10'
alias copy='xclip -sel clip'
alias za='tree -aL 4 -I ".git" '
alias reload='source ~/.aliases'
# Undo something removed, using git (if it was previously in git)
function unrm() {
git checkout $(git rev-list -n 1 HEAD -- "$1")^ -- "$1"
}
# Change directory for projects/apps
alias cda='cd ~/apps'
alias cdp='cd ~/projects'
alias cdg='cd ~/github'
# From https://madebynathan.com/2011/10/04/a-nicer-way-to-use-xclip/
# A shortcut function that simplifies usage of xclip.
# - Accepts input from either stdin (pipe), or params.
# ------------------------------------------------
cb() {
local _scs_col="\e[0;32m"; local _wrn_col='\e[1;31m'; local _trn_col='\e[0;33m'
# Check that xclip is installed.
if ! type xclip > /dev/null 2>&1; then
echo -e "$_wrn_col""You must have the 'xclip' program installed.\e[0m"
# Check user is not root (root doesn't have access to user xorg server)
elif [[ "$USER" == "root" ]]; then
echo -e "$_wrn_col""Must be regular user (not root) to copy a file to the clipboard.\e[0m"
else
# If no tty, data should be available on stdin
if ! [[ "$( tty )" == /dev/* ]]; then
input="$(< /dev/stdin)"
# Else, fetch input from params
else
input="$*"
fi
if [ -z "$input" ]; then # If no input, print usage message.
echo "Copies a string to the clipboard."
echo "Usage: cb <string>"
echo " echo <string> | cb"
else
# Copy input to clipboard
echo -n "$input" | xclip -selection c
# Truncate text for status
if [ ${#input} -gt 80 ]; then input="$(echo $input | cut -c1-80)$_trn_col...\e[0m"; fi
# Print status.
echo -e "$_scs_col""Copied to clipboard:\e[0m $input"
fi
fi
}
# Aliases / functions leveraging the cb() function
# ------------------------------------------------
# Copy contents of a file
function cbf() { cat "$1" | cb; }
# Copy SSH public key
alias cbssh="cbf ~/.ssh/id_rsa.pub"
# Copy current working directory
alias cbwd="pwd | cb"
# Copy most recent command in bash history
alias cbhs="cat $HISTFILE | tail -n 1 | cb"
# Open this file for editing
alias vaa="vim $HOME/.aliases"