-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions
More file actions
143 lines (121 loc) · 3.94 KB
/
functions
File metadata and controls
143 lines (121 loc) · 3.94 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/bash
command_exists() {
type "$1" &>/dev/null
}
# Pull all git repos one level below current directory
# TODO: Broken, test and fix portability
pullall() {
find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree="$PWD"/{} pull origin master \;
}
# Deduplicate path variables, shell-agnostic
# TODO: use to cleanup env after logging in
# TODO: probably problematic, test.
get_var() { eval "echo \$$1"; }
set_var() { eval "$1=\"$2\""; }
dedup_pathvar() {
pathvar_name="$1"
pathvar_value="$(get_var $pathvar_name)"
deduped_path="$(echo -n $pathvar_value | perl -e 'print join(":",grep { not $seen{$_}++ } split(/:/, scalar <>))')"
set_var $pathvar_name "$deduped_path"
}
# https://coderwall.com/p/_s_xda/fix-ssh-agent-in-reattached-tmux-session-shells
fixssh() {
for key in SSH_AUTH_SOCK SSH_CONNECTION SSH_CLIENT; do
if (tmux show-environment | grep "^${key}" >/dev/null); then
value=$(tmux show-environment | grep "^${key}" | sed -e "s/^[A-Z_]*=//")
export ${key}="${value}"
fi
done
}
# Shorten the email to the format x@y; useful in prompt
git_user_name_prompt_mkii() {
gitname=$(git config user.email | sed 's/\(.\).\+@\(..\).\+/\1@\2/')
gitname_global=$(git config --global user.email | sed 's/\(.\).\+@\(..\).\+/\1@\2/')
if [[ $gitname != $gitname_global ]]; then
#echo -n $gitname | color red
echo -n $gitname
else
echo -n $gitname
fi
}
# Which commands are most commonly used?
# (use this information to improve workflow)
history-high-score() {
history | awk '{print $2}' | awk 'BEGIN {FS="|"} {print $1}' | sort | uniq -c | sort
}
# Set a random colorscheme
#random-base16-colorscheme() {
#pushd . >/dev/null &&
#cd "$HOME/.local/share/base16/templates/shell/scripts" &&
#colorscheme=$(ls *.sh | shuf | head -1) &&
#echo $colorscheme &&
#source $colorscheme &&
#popd >/dev/null
#}
# git quicksave: commit and push
save() {
if [ -z "${1+x}" ]; then
#echo "Missing commit message.";
git commit -a -m "update" && git push
else
git commit -a -m "$1" && git push
fi
}
# Print the argument in the terminal, centered
function center-text() {
#colcount=$((`tput cols` - 1))
colcount=$((COLUMNS - 3))
sed -e :a -e "s/^.\{1,$colcount\}$/ & /;ta"
unset colcount
}
# Neovim launchers
n() {
if command_exists nvim; then
nvim "$@"
else
vim "$@"
fi
#if [ $# -eq 0 ]; then
## nvim "$(fzf)"
#nvim "$@"
#else
#nvim "$@"
#fi
}
#motd() {
#echo " Juice-tone, we ain't got no problem " | center-text | color yellow
#}
function hsi() {
#history | fzf --tac --no-sort --query="$1"
history | grep -E -i "$1"
}
function esi() {
#env | sort | fzf --query="$1"
env | grep -E -i "$1"
}
function zen() {
prompt_powerlevel9k_teardown
clear
export PROMPT=" "
#export PROMPT=" "
}
function unzen() {
prompt_powerlevel9k_setup
}
nerdfont_icon_search() {
cat $RUNCOM_PATH/utils/nerd-fonts-scripts/*.sh | sed "s/i=//" | sed "s/=\$i//" | grep -E "^'" | sed "s/'//g" | sort --random-sort | fzf | perl -ne 'print $1 if /^([^ ]+) /' # | xsel --input
}
function emoji_search() {
emojify -l | tail -n +5 | sort | fzf
}
#transfer() { if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi
#tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile; rm -f $tmpfile; }
function tiv() {
docker run --rm -v "$(pwd):/home" bperel/terminalimageviewer "$1" -w "$(tput cols)"
}
function tivd() {
docker run --rm -v "$(pwd):/home" bperel/terminalimageviewer "$1" -w "$(tput cols)" -d "?(*.png|*.jpg)"
}
function show_colormap() {
for i in {0..255}; do print -Pn "%${i}F${(l:3::0:)i}%f " ${${(M)$((i%8)):#7}:+$'\n'}; done
}