-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.aliases
97 lines (86 loc) · 3.1 KB
/
.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# custom-made aliases
alias install="sudo apt install"
alias update="sudo apt update"
alias upgrade="sudo apt upgrade"
alias remove="sudo apt remove"
alias purge="sudo apt remove --purge"
alias search="aptitude search"
alias show="apt show"
alias up2="sudo apt update && sudo apt upgrade"
# gcp is a cp with progress bar
unalias "gcp"
alias py="python"
alias ipy="ipython --pylab"
alias pyd="python -m ipdb -c"
alias pingo="ping google.com"
alias t="tmux"
alias v="vim"
alias e="vim"
alias mk="make"
# Git aliases in addition to oh-my-zsh
alias gshow="git show"
alias gdiff="git diff"
alias gdiffc="git diff --cached"
alias gdc="git diff --cached"
alias op="xdg-open"
alias nau="nautilus ."
alias sa="source activate"
unalias "ll"
unalias "l"
alias l="ls -l"
alias ll="ls -la"
alias h="fc -i -l 1"
alias freecache="sudo bash -c 'echo Before: && free -h && swapoff -a && sync && echo 2 > /proc/sys/vm/drop_caches && swapon -a && echo && echo After: && free -h'"
# This is not really an alias because it appends some stuff at the end
function ssh () {/usr/bin/ssh -t $@ "tmux attach -t loginbase || tmux new -s loginbase";}
function tn () {TMUX=`tmux new-session -d -s $1` && tmux switch-client -t $1;}
function ts () {tmux switch-client -t $1;}
function tls () {echo 'tmux Sessions:'; tmux list-sessions;}
function tk () {tmux kill-session -t $1;}
# 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 cbh="cat $HISTFILE | tail -n 1 | cb"
# Copy real absolute path of a file
function cbpath() { realpath "$1" | cb; }
function mkdircd(){ mkdir -p $1 && cd $1 ; }
function jl(){ jq < $1 | less ; }