-
Notifications
You must be signed in to change notification settings - Fork 20
/
openeditor
executable file
·70 lines (65 loc) · 1.39 KB
/
openeditor
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
#!/bin/bash
# opens a file in the editor of your choice
# good thing: it checks which editor is open and opens the file in that editor
# if no editor is found it defaults to a lightweight editor (like kwrite)
# the order in which to execute the commands
# breaks on success
# available are the following commands:
#
# kwrite_new_win
# quanta_new_win
# kate_new_win
#
# quanta_new_tab
# kate_new_tab
#
order=(
quanta_new_tab
kate_new_tab
kwrite_new_win
)
# nothing should be changed below
# new kate tab
function kate_new_tab {
isrunning kate || return 1
echo "open file in a new kate tab:"
kate -u "$1"
}
# new kate window
function kate_new_win {
echo "open file in kate:"
kate "$1"
}
# new kwrite window
function kwrite_new_win {
echo "open file in kwrite:"
kwrite "$1"
}
# new quanta window
function quanta_new_win {
echo "open file in quanta:"
quanta "$1"
}
# new quanta tab
function quanta_new_tab {
isrunning quanta || return 1
echo "open file in new quanta tab:"
quanta --unique "$1"
}
# check if a process is running
function isrunning {
pid=(`pidof $1`)
return `[[ ${pid[0]} ]]`
}
# cached konqueror file
if [[ ${1#/tmp/kde} != $1 || ${1#/var/tmp/kdecache} != $1 ]]; then
#echo "cache" >> /home/milian/.bin/editorlog
# cached file
kwrite "$1"
exit
fi
# call functions based on order defined above
for i in `seq 1 ${#order[@]}`;
do
${order[$i-1]} "$1" && exit 0
done