aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/usr/include/drive-google/aliases
blob: 9ca511b7857986adbf9df7003a2e45ceac292338 (about) (plain)
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
###################################################################################################
# aliases
###################################################################################################
# Copyright 2017-2018 Jean-Christophe Manciot <manciot.jeanchristophe@gmail.com>
#
# Licensed under a GPLv3 License.
# You may not use this file except in compliance with the License. You may obtain a copy of the 
# License at:
#
#    https://www.gnu.org/licenses/gpl-3.0.md
#
# The licensor cannot revoke these freedoms as long as you follow the license terms.
#
# Attribution — You must give appropriate credit, provide a link to the license, and indicate if 
#               changes were made. You may do so in any reasonable manner, but not in any way that 
#               suggests the licensor endorses you or your use.
###################################################################################################

###################################################################################################
#
# Defining some aliases for sed/grep/awk/perl commands for simplicity & readability sake
#
###################################################################################################
#
# Usage example:
# -------------
#
# shopt -s expand_aliases
# . /usr/include/drive-google/aliases
#
###################################################################################################

#------------------------------------Escaping------------------------------------------------------
# Escaping the '$.*/[\]^' characters for later sed searched string
# Letters, digits and '(){}+?|' must not be escaped
# It ***cannot*** be used with '|' as a separator in the sed expression
alias escape_sed_bre_search_string=$'sed -e \'s|[]\/$.*^[]|\\\&|g\''

# Escaping the '$./[\]^' characters for later sed searched string
# Letters, digits and '(){}+?|*' are not escaped
alias escape_limited_sed_bre_search_string=$'sed -e \'s|[]\/$.^[]|\\\&|g\''

# Escaping the '/\&' characters for later sed replacement string
alias escape_sed_bre_replacement_string=$'sed -e \'s|[/\&]|\\\&|g\''

# Escaping the '$.\^(){}+[]' characters for later grep -P searched string
# Letters, digits and '-' must not be escaped
# '/?*|' are not escaped
alias escape_grep_search_string=$'sed -e \'s|[]$.\^(){}+[]|\\\&|g\''

# Escaping all "escape sequences"
alias escape_escape_sequences=$'sed \'s%\o033\[..m%%g\''

# Escaping single quotes for later eval
# Thanks to @Vouze in http://unix.stackexchange.com/questions/344644/escaping-single-quotes-with-an-alias
alias escape_single_quotes="sed \"s/'/\\\\\\\\'/g\""

# Escaping double quotes for later eval
alias escape_double_quotes=$'sed \'s|"|\\\\"|g\''

#------------------------------------Replacing----------------------------------------------------
# Replacing some standard wildcards by their regular expression equivalent ([] are left unmodified)
# + ? --> .
# + * --> .*
alias replace_wildcards_regex=$'sed -e \'s|?|.|g; s|\\*|.*|g\''

#------------------------------------Removing------------------------------------------------------
# Removing leading object stats
alias rm_object_stats=$'perl -pe \'s|^. ([0-9]+.*?B) ||\''

# Removing all occurrences of '&' in $object as a workaround to a markup ampersand issue with zenity
alias rm_ampersand=$'sed \'s|&||g\''

# Removing local path from <google_drive_root_folder> 
alias rm_path_from_gd_root='sed "s/${esc_local_folder_path_from_gd_root}\/${esc_sobject}/${esc_robject}/g"'

# Removing full object name
alias rm_object='sed "s/^${esc_local_folder_path_from_gd_root}\/${esc_object}:\\s//g"'

# Removing leading !
alias rm_not=$'sed \'s|^!||\''

# Removing leading ./
alias rm_dot_slash=$'sed \'s|^\./||g\''

# Removing:
# + the object type (d: folder and -:file) 
# + the object size (in B, KB, MB, TB...))
# + the excluded object path name
alias rm_object_type_size_excluded_object_path='sed "s/^. [0-9]\+.*B ${esc_excluded_object_path}$//"'

#------------------------------------Extracting----------------------------------------------------
# Extracting the leading object type
alias extract_object_type=$'sed -E \'s|^(.).*|\\1|\''

# Extracting:
# + the object type (d: folder and -:file) 
# + the object size (in B, KB, MB, TB...))
# + the object name without its $local_folder_path_from_gd_root/ (all returned objects path start at GD root folder)
alias extract_object_type_size_name='sed "s/^\(.\).* \([0-9]\+.*B\) .*UTC\s*${esc_local_folder_path_from_gd_root}\//\1 \2 /g"'

# Extracting object size with perl: sed does not recognize the non-greedy quantifier '?'
alias extract_object_size=$'perl -pe \'s|^. ([0-9]+.*?B) .*|\\1|\''

# Extracting object size multiplier with perl: sed does not recognize the non-greedy quantifier '?'
alias extract_object_size_multiplier=$'perl -pe \'s|^[0-9]+.*?(.B)|\\1|\''

# Extracting object id
alias extract_object_id=$'grep -P "${grep_esc_object}$" | awk \'{print $4}\''

# Extracting Shared boolean
alias extract_shared=$'sed -e \'s/^Shared *//\''

# Extracting Starred boolean
alias extract_starred=$'sed -e \'s/^Starred *//\''

# Extracting ModTime
alias extract_modtime=$'sed -e \'s/^ModTime *//\''

# Extracting URL
alias extract_url=$'sed -e \'s|^.*https|https|g\''

# Extracting standard wildcards
alias extract_standard_wildcards=$'sed -E \'s|[^*?]||g\''

#------------------------------------Inserting-----------------------------------------------------
# Inserting a separator (with a new line)
alias insert_separator=$'sed -e \'1s;^;--------------------------------------------\\\n;\''

# Inserting a new line
alias insert_new_line='grep ".*"'

#------------------------------------Prepending----------------------------------------------------
# Prepending a separator (without a new line)
alias prepend_separator=$'sed -e \'1s;^;--------------------------------------------;\''

#------------------------------------Selecting----------------------------------------------------
# Selecting the object name
alias select_object='grep -P "$grep_esc_object"'

# Selecting $folder
alias select_folder='grep -P "$grep_esc_folder"'

# Selecting $gd_root_folder
alias select_gd_root_folder='grep -P "$grep_esc_gd_root_folder"'

# Selecting AccountType
alias select_AccountType='grep "AccountType"'

# Selecting duplicate
alias select_duplicate='grep -E "No duplicate|Fixed duplicate"'

# Selecting Deleted
alias select_Deleted='grep "Deleted"'

# Selecting LastModifyingUsername
alias select_LastModifyingUsername='grep "LastModifyingUsername"'

# Selecting Name
alias select_Name='grep "Name"'

# Selecting OriginalFilename
alias select_OriginalFilename='grep "OriginalFilename"'

# Selecting Role
alias select_Role='grep "Role"'

# Selecting Shared
alias select_Shared='grep "Shared"'

# Selecting Starred
alias select_Starred='grep "Starred"'

# Selecting Published
alias select_Published='grep "Published"'

# Selecting Pulled
alias select_Pulled='grep "Pulled"'

# Selecting Pushed
alias select_Pushed='grep "Pushed"'

# Selecting Shared
alias select_Shared='grep "Shared"'

# Selecting Touched
alias select_Touched='grep "Touched"'

# Selecting Trashed
alias select_Trashed='grep "Trashed"'

# Selecting Unpublished
alias select_Unpublished='grep "Unpublished"'

# Selecting Unshared
alias select_Unshared='grep "Unshared"'

# Selecting Untrashed
alias select_Untrashed='grep "Untrashed"'

# Selecting delimiter
alias select_delimiter='grep -E -- "--------------------------------------------"'

# Selecting Unknown object type
alias select_Unknown_object_type='grep "Unknown object type"'