-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell-aliases
161 lines (144 loc) · 4.83 KB
/
shell-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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# vim goodness
alias :sp='test -n "$TMUX" && tmux split-window'
alias :vs='test -n "$TMUX" && tmux split-window -h'
alias :q='exit'
# ls
if command -v eza &> /dev/null;
then
alias ls='eza --color=never'
fi
alias ll='ls -alF'
alias cl='clear'
# dir manipulation
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias compare='diff -rq'
# git
alias g='git'
alias it='git' # fat fitngers
alias ga='git add'
alias gap='git add -p'
alias gs='git status -s'
alias gc='git commit -m'
# tmux aliases
alias tst='tmux start-server'
alias tks='tmux kill-server'
alias tl='tmux list-sessions'
# attach to existing or start a named session by providing a name
# or a blank session by calling `tm`
tm() {
if [ $# -eq 0 ]; then
# No arguments provided; start tmux normally
tmux
else
local session_name="$1"
# Check if the session already exists
if tmux has-session -t "$session_name" 2>/dev/null; then
# Session exists; attach to it
tmux attach-session -t "$session_name"
else
# Session does not exist; create a new one
tmux new-session -s "$session_name"
fi
fi
}
# other aliases
alias e='exit'
alias o='open .'
alias ax='chmod a+x'
alias h='eval $(history | fzf +s --tac --tiebreak=index | sed "s/ *[0-9]* *//")'
alias q='quit'
alias chux='chmod u+x'
export NOTES_PATH="$HOME"/Documents/notes
function notes()
{
# If there is no "notes" window, rename the current one
if [[ -n "$TMUX" ]]; then
has_notes_window=$(tmux list-windows | grep notes)
[ "$has_notes_window" ] || tmux rename-window "notes"
fi
eval PWD=$NOTES_PATH $EDITOR -c "NotesStart"
}
alias colorlight="~/dot-files/scripts/base16-github.sh"
alias colordark="~/dot-files/scripts/base16-tomorrow-night.sh"
alias nvi="~/Downloads/nvim-macos-arm64/bin/nvim"
alias nnvim="~/Downloads/nvim-nightly/bin/nvim"
function cdf()
{
cd "$(fd --type d --exclude node_modules | fzf)"
}
function cdF()
{
cd "$(fd --type d --no-ignore --exclude node_modules | fzf)"
}
function repo_url()
{
# get origin
# - [email protected]:user/repo.git
# - https://github.foobar.com:user/repo
#
# 1. replace `:` between host and user
# 2. remove `git@` in the beginning if present
# 3. remove `.git` in the end if present
# 4. remove `:` in the protocol if it was affected by step 1
git config remote.origin.url \
| sed 's/:/\//' \
| sed -re 's/^git@/https:\/\//g' \
| sed 's/\.git$//' \
| sed 's/^https\//https:/'
}
# brew_upgrade_outdated
function bu() {
brew update --quiet
# List outdated packages and use fzf to allow the user to select multiple packages
local packages_to_upgrade=$(brew outdated --quiet | fzf --multi --border --prompt "Select packages to upgrade: " | awk '{printf "%s ", $1}')
# Check if the user selected any packages
if [[ -n "$packages_to_upgrade" ]]; then
# Upgrade the selected packages in one command
echo "Upgrading selected packages: $packages_to_upgrade"
eval brew upgrade --quiet "$packages_to_upgrade"
else
echo "No packages selected for upgrade."
fi
}
alias bua="brew update --all && brew upgrade && brew cleanup --quiet"
function docker_stop_all() {
docker stop $(docker ps -q)
}
function get_nvim_nightly() {
local old_pwd=$(pwd)
cd ~/Downloads
# clean up if it exists already
rm -rf ./nvim-macos-arm64.tar.gz ./nvim-macos-arm64 ./nvim-nightly
# download tar with build
wget --quiet https://github.com/neovim/neovim/releases/download/nightly/nvim-macos-arm64.tar.gz && echo "- Downloaded"
# to avoid "unknown developer" warning
xattr -c ./nvim-macos-arm64.tar.gz > /dev/null 2>&1 && echo "- Removed attributes"
# extract
tar xzvf nvim-macos-arm64.tar.gz > /dev/null 2>&1 && echo "- Extracted"
mv nvim-macos-arm64 nvim-nightly
~/Downloads/nvim-nightly/bin/nvim --version | grep 'NVIM v'
# print archive date
echo "Build from: $(ls -l ~/Downloads/nvim-macos-arm64.tar.gz | awk '{print $6, $7, $8}')"
cd $old_pwd
}
function get_nvim() {
local old_pwd=$(pwd)
cd ~/Downloads
# clean up if it exists already
rm -rf ./nvim-macos-arm64.tar.gz ./nvim-macos-arm64 ./nvim
# download tar with build
wget --quiet https://github.com/neovim/neovim/releases/download/v0.10.0/nvim-macos-arm64.tar.gz && echo "- Downloaded"
# to avoid "unknown developer" warning
xattr -c ./nvim-macos-arm64.tar.gz > /dev/null 2>&1 && echo "- Removed attributes"
# extract
tar xzvf nvim-macos-arm64.tar.gz > /dev/null 2>&1 && echo "- Extracted"
mv nvim-macos-arm64 nvim
~/Downloads/nvim/bin/nvim --version | grep 'NVIM v'
# print archive date
echo "Build from: $(ls -l ~/Downloads/nvim-macos-arm64.tar.gz | awk '{print $6, $7, $8}')"
cd $old_pwd
}