-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit
executable file
·54 lines (48 loc) · 1.94 KB
/
edit
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
#!/usr/bin/zsh
# vim: set filetype=bash:
# TODO:
# - Break out the -s and -a options into their own case statement.
# - Implicitly try for scripts and alias files if no shortcut found?
# - Search system for any file and select with fzf?
# - Allow shortcut definitions with an external config file?
# - Add a usage string.
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
-c ) EDITOR="code"; ARG="$2" ;;
-n ) EDITOR="nano"; ARG="$2" ;;
-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.
;;
-a ) FILE=$(fd "$2" "$ALIASES.aliases")
[[ $FILE == "" ]] && FILE="$ALIASES/$2.aliases"
ARG=""
;;
-p ) FILE=$(fd "$2" "$NVIM_PLUGINS")
ARG=""
;;
* ) ;;
esac
case "$ARG" in
zrc ) FILE="$ZDOTDIR/.zshrc" ;;
env ) FILE="$ZDOTDIR/.zshenv" ;;
aliases ) FILE="$XDG_CONFIG_HOME/.aliases/.aliases" ;;
vrc ) FILE="$XDG_CONFIG_HOME/nvim/lua/custom/init.lua" ;;
qtile ) FILE="$XDG_CONFIG_HOME/qtile/config.py" ;;
prompt ) FILE="$XDG_CONFIG_HOME/.prompt" ;;
gitconfig ) FILE="$XDG_CONFIG_HOME/git/config" ;;
term ) FILE="$XDG_CONFIG_HOME/alacritty.yml" ;;
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" ;;
ssh ) FILE="$HOME/.ssh/config" ;;
esac
[[ "$FILE" != "" ]] && $EDITOR $FILE || echo "No such file."
}