forked from AdrianDC/advanced_development_shell_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
android_host.rc
179 lines (148 loc) · 3.87 KB
/
android_host.rc
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
#
# Copyright 2015-2017 Adrian DC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# === Standalone Source Helper ===
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/android_host.rc)
# === File Editor ===
function fileedit()
{
# Usage
if [ -z "${1}" ]; then
echo '';
echo ' Usage: fileedit <paths> (Files editor for most environments)';
echo '';
return;
fi;
# Variables
local opened;
# Files editor for most environments
for file in "${@}"; do
# If option enabled, create missing files
if [ ! -z "${FILEEDIT_TOUCH_NEW_FILE}" ] && [ ! -f "${file}" ]; then
mkdir -p "${file%/*}";
touch "${file}";
# Filter only files
elif [ ! -f "${file}" ]; then
echo " fileedit: '${file}' not found";
continue;
fi;
# Resolve symlink paths
file=$(readlink -f "${file}");
# GUI xdg editor
xdg-open "${file}" 2> /dev/null;
opened=${?};
# GUI notepad++ editor
if [ ${opened} -ne 0 ] && [ ! -z "$(type -t notepad++ 2> /dev/null)" ]; then
[ "$(nohup notepad++ -nosession "${file}" > /dev/null 2>&1 & echo ${?})" -eq 0 ] && opened=0;
fi;
# Terminal nano editor
if [ ${opened} -ne 0 ] && [ ! -z "$(type -t nano 2> /dev/null)" ]; then
nano "${file}";
opened=${?};
fi;
# Terminal vim editor
if [ ${opened} -ne 0 ] && [ ! -z "$(type -t vim 2> /dev/null)" ]; then
vim "${file}";
opened=${?};
fi;
# Unknown environment
if [ ${opened} -ne 0 ]; then
echo " Found in ${file}";
fi;
done;
}
# === File Editor Shortcut ===
alias fe='fileedit';
alias fen='FILEEDIT_TOUCH_NEW_FILE=true fileedit';
# === Director Opener ===
function diropen()
{
# Usage
if [ ! -d "${1}" ]; then
echo '';
echo ' Usage: diropen <path> (Directory opener for most environments)';
echo '';
return;
fi;
# Variables
local opened;
# GUI xdg directory viewer
xdg-open "${1}" 2> /dev/null;
opened=${?};
# GUI explorer directory viewer
if [ ${opened} -ne 0 ] && [ ! -z "$(type -t explorer 2> /dev/null)" ]; then
explorer "${1//\//\\}";
opened=0;
fi;
# Unknown environment
if [ ${opened} -ne 0 ]; then
cd "${1}";
fi;
}
# === Directory Opener Shortcut ===
alias dop='diropen .';
# === URL Opener ===
function urlopen()
{
# Usage
if [ -z "${1}" ]; then
echo '';
echo ' Usage: urlopen <url> (URL opener for most environments)';
echo '';
return;
fi;
# Variables
local opened;
# GUI xdg url viewer
xdg-open "${1}" 2> /dev/null;
opened=${?};
if [ ${opened} -eq 0 ]; then
echo '';
sleep 1;
echo '';
fi;
# Unknown environment
if [ ${opened} -ne 0 ]; then
echo '';
echo " Url: ${1}";
echo '';
fi;
}
# === Desktop Path ===
function desktoppath()
{
# Usage: desktoppath (Acquire desktop path for most environments)
# Variables
local path;
# Environment ANDROID_DESKTOP override
path="${ANDROID_DESKTOP}";
# Fallback to GUI xdg path
if [ -z "${path}" ]; then
path=$(xdg-user-dir DESKTOP 2>/dev/null);
fi;
# Fallback to environment ANDROID_DEV_DRIVE path
if [ -z "${path}" ] && [ ! -z "${ANDROID_DEV_DRIVE}" ]; then
path="${ANDROID_DEV_DRIVE}/Desktop";
mkdir -p "${path}/";
fi;
# Fallback to home path
if [ -z "${path}" ]; then
path=~/Desktop;
mkdir -p "${path}/";
fi;
# Return path
echo "${path}";
}