-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit
More file actions
executable file
·59 lines (51 loc) · 2.29 KB
/
edit
File metadata and controls
executable file
·59 lines (51 loc) · 2.29 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
#!/usr/bin/env zsh
# vim: set filetype=bash:
edit() {
local EDITOR="$EDITOR"
local FILE=""
local SCRIPTS="$HOME/.scripts/"
local ALIASES="$XDG_CONFIG_HOME/.aliases/"
local NVIM_PLUGINS="$XDG_CONFIG_HOME/nvim/lua/plugins/"
local ARG="$1"
case "$ARG" in
# Open in a specific editor
-c ) EDITOR="code"; ARG="$2" ;;
-n ) EDITOR="nano"; ARG="$2" ;;
# Open a specific script
-s ) FILE=$(fd "^$2$" $SCRIPTS)
[[ $FILE == "" ]] && FILE="$SCRIPTS/$2" # Open a new buffer.
ARG="" # Set ARG to empty string so it is ignored in the next case statement.
;;
# Open a specific alias file
-a ) FILE=$(fd "$2" "$ALIASES.aliases")
[[ $FILE == "" ]] && FILE="$ALIASES/$2.aliases"
ARG=""
;;
# Open a specific nvim plugin
-p ) FILE=$(fd "$2" "$NVIM_PLUGINS")
ARG=""
;;
* ) ;;
esac
case "$ARG" in
z | sh | zrc ) FILE="$ZDOTDIR/.zshrc" ;;
e | env ) FILE="$ZDOTDIR/.zshenv" ;;
a | aliases ) FILE="$XDG_CONFIG_HOME/.aliases/.aliases" ;;
g | term | ghostty ) FILE="$XDG_CONFIG_HOME/ghostty" ;;
q | wm | qtile ) FILE="$XDG_CONFIG_HOME/qtile/" ;;
n | nvim ) FILE="$XDG_CONFIG_HOME/nvim/" ;;
s | scripts ) FILE="$HOME/.scripts/" ;;
o | obsidian ) FILE="$HOME/documents/obsidian/Personal/.obsidian/snippets/" ;;
df | dotfiles ) FILE="$HOME/src/github/dotfiles/" ;;
ssh ) FILE="$HOME/.ssh/config" ;;
prompt ) FILE="$XDG_CONFIG_HOME/.prompt" ;;
gitconfig ) FILE="$XDG_CONFIG_HOME/git/config" ;;
nf ) FILE="$XDG_CONFIG_HOME/neofetch/config.conf" ;;
xsession ) FILE="$XDG_CONFIG_HOME/.xsession" ;;
picom ) FILE="$XDG_CONFIG_HOME/picom.conf" ;;
hk ) FILE="$XDG_CONFIG_HOME/.sxhkdrc" ;;
esac
[[ "$FILE" != "" ]] \
&& { pushd $(dirname $FILE) && $EDITOR $FILE && popd ; } \
|| { echo "No such file." ; }
}