-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim
executable file
·64 lines (61 loc) · 1.45 KB
/
vim
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
#!/bin/bash
#===============================================================================
#
# FILE: edit.sh
#
# USAGE: ./edit.sh
#
# DESCRIPTION: Simple script that runs editor as sudo if necessary.
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Chevalier de Balibari ([email protected]),
# ORGANIZATION: ---
# CREATED: 04/11/2019 09:22:29 AM
# REVISION: ---
#===============================================================================
#set default editor
if [ -z $VIM_PATH ]; then
VIM_PATH=/usr/bin/lvim
fi
#check if an argument is provided
if [ -z $1 ]
then
#open editor only, no argument is provided
$VIM_PATH
else
#test if file exists
if [ ! -f $1 ]
then
#file don't exist, destination folder permissions apply
FILE_PATH=$1
DESTINATION_FOLDER_PATH=${FILE_PATH%/*}
#test if path or filename is provided
if [ $FILE_PATH == $DESTINATION_FOLDER_PATH ]
then
#destination folder path is current working directory
DESTINATION_FOLDER_PATH=$PWD
fi
#check if destination folder is writable by user
if [ -w $DESTINATION_FOLDER_PATH ]
then
#open editor as ordinary user
$VIM_PATH $FILE_PATH
else
#open editor as sudo user
sudo $VIM_PATH $FILE_PATH
fi
#file exists, file permissions apply
else
if [ -w $1 ]
then
#open editor as ordinary user
$VIM_PATH $1
else
#open editor as sudo user
sudo $VIM_PATH $1
fi
fi
fi