@@ -8,7 +8,7 @@ function editpost() {
88 group ' jekyll'
99
1010 local SITE site POST DATE TITLE POSTS
11- local -i COUNTER=1 POST_TO_EDIT
11+ local -i COUNTER=1 POST_TO_EDIT ret
1212 if [[ -z " ${1:- } " ]]; then
1313 echo " Error: no site specified."
1414 echo " The site is the name of the directory your project is in."
@@ -27,7 +27,7 @@ function editpost() {
2727 return 1
2828 fi
2929
30- builtin cd " ${SITE} /_posts" || return
30+ pushd " ${SITE} /_posts" > /dev/null || return
3131
3232 for POST in * ; do
3333 DATE=" $( echo " ${POST} " | grep -oE " [0-9]{4}-[0-9]{1,2}-[0-9]{1,2}" ) "
@@ -36,9 +36,12 @@ function editpost() {
3636 echo " ${COUNTER} ) ${DATE} ${TITLE} "
3737 POSTS[COUNTER]=" $POST "
3838 COUNTER=" $(( COUNTER + 1 )) "
39- done | less
39+ done > >( less)
4040 read -rp " Number of post to edit: " POST_TO_EDIT
4141 " ${JEKYLL_EDITOR:- ${VISUAL:- ${EDITOR:- ${ALTERNATE_EDITOR:- nano} } } } " " ${POSTS[POST_TO_EDIT]} "
42+ ret=" $? "
43+ popd > /dev/null || return " $ret "
44+ return " $ret "
4245}
4346
4447function newpost() {
@@ -48,7 +51,7 @@ function newpost() {
4851
4952 local SITE site FNAME_POST_TITLE FNAME YAML_DATE
5053 local JEKYLL_FORMATTING FNAME_DATE OPTIONS OPTION POST_TYPE POST_TITLE
51- local -i loc=0
54+ local -i loc=0 ret
5255 if [[ -z " ${1:- } " ]]; then
5356 echo " Error: no site specified."
5457 echo " The site is the name of the directory your project is in."
@@ -69,62 +72,29 @@ function newpost() {
6972 loc=$(( loc + 1 ))
7073 done
7174
72- # 'builtin cd' into the local jekyll root
73-
74- builtin cd " ${SITE} /_posts" || return
75+ # Change directory into the local jekyll root
76+ pushd " ${SITE} /_posts" > /dev/null || return
7577
7678 # Get the date for the new post's filename
77-
7879 FNAME_DATE=" $( date " +%Y-%m-%d" ) "
7980
8081 # If the user is using markdown or textile formatting, let them choose what type of post they want. Sort of like Tumblr.
81-
8282 OPTIONS=(' Text' ' Quote' ' Image' ' Audio' ' Video' ' Link' )
8383
8484 if [[ $JEKYLL_FORMATTING == " markdown" || $JEKYLL_FORMATTING == " textile" ]]; then
8585 select OPTION in " ${OPTIONS[@]} " ; do
86- if [[ $OPTION == " Text" ]]; then
87- POST_TYPE=" Text"
88- break
89- fi
90-
91- if [[ $OPTION == " Quote" ]]; then
92- POST_TYPE=" Quote"
93- break
94- fi
95-
96- if [[ $OPTION == " Image" ]]; then
97- POST_TYPE=" Image"
98- break
99- fi
100-
101- if [[ $OPTION == " Audio" ]]; then
102- POST_TYPE=" Audio"
103- break
104- fi
105-
106- if [[ $OPTION == " Video" ]]; then
107- POST_TYPE=" Video"
108- break
109- fi
110-
111- if [[ $OPTION == " Link" ]]; then
112- POST_TYPE=" Link"
113- break
114- fi
86+ POST_TYPE=" ${OPTION} "
87+ break
11588 done
11689 fi
11790
11891 # Get the title for the new post
119-
12092 read -rp " Enter title of the new post: " POST_TITLE
12193
12294 # Convert the spaces in the title to hyphens for use in the filename
123-
12495 FNAME_POST_TITLE=" ${POST_TITLE/ / -} "
12596
12697 # Now, put it all together for the full filename
127-
12898 FNAME=" $FNAME_DATE -$FNAME_POST_TITLE .$JEKYLL_FORMATTING "
12999
130100 # And, finally, create the actual post file. But we're not done yet...
@@ -151,72 +121,65 @@ function newpost() {
151121 } > " ${FNAME} "
152122
153123 # Generate template text based on the post type
154-
155124 if [[ $JEKYLL_FORMATTING == " markdown" ]]; then
156- if [[ $POST_TYPE == " Text" ]]; then
157- true
158- fi
159-
160- if [[ $POST_TYPE == " Quote" ]]; then
161- echo " > Quote"
162- echo
163- echo " — Author"
164- fi
165-
166- if [[ $POST_TYPE == " Image" ]]; then
167- echo " "
168- fi
169-
170- if [[ $POST_TYPE == " Audio" ]]; then
171- echo " <html><audio src=\" /path/to/audio/file\" controls=\" controls\" ></audio></html>"
172- fi
173-
174- if [[ $POST_TYPE == " Video" ]]; then
175- echo " <html><video src=\" /path/to/video\" controls=\" controls\" ></video></html>"
176- fi
177-
178- if [[ $POST_TYPE == " Link" ]]; then
179- echo " [link][1]"
180- echo
181- echo " > Quote"
182- echo
183- echo " [1]: url"
184- fi
185- fi >> " ${FNAME} "
186-
187- if [[ $JEKYLL_FORMATTING == " textile" ]]; then
188- if [[ $POST_TYPE == " Text" ]]; then
189- true
190- fi
191-
192- if [[ $POST_TYPE == " Quote" ]]; then
193- echo " bq. Quote"
194- echo
195- echo " — Author"
196- fi
197-
198- if [[ $POST_TYPE == " Image" ]]; then
199- echo " !url(alt text)"
200- fi
201-
202- if [[ $POST_TYPE == " Audio" ]]; then
203- echo " <html><audio src=\" /path/to/audio/file\" controls=\" controls\" ></audio></html>"
204- fi
205-
206- if [[ $POST_TYPE == " Video" ]]; then
207- echo " <html><video src=\" /path/to/video\" controls=\" controls\" ></video></html>"
208- fi
209-
210- if [[ $POST_TYPE == " Link" ]]; then
211- echo " \" Site\" :url"
212- echo
213- echo " bq. Quote"
214- fi
125+ case $POST_TYPE in
126+ " Text" )
127+ true
128+ ;;
129+ " Quote" )
130+ echo " > Quote"
131+ echo
132+ echo " — Author"
133+ ;;
134+ " Image" )
135+ echo " "
136+ ;;
137+ " Audio" )
138+ echo " <html><audio src=\" /path/to/audio/file\" controls=\" controls\" ></audio></html>"
139+ ;;
140+ " Video" )
141+ echo " <html><video src=\" /path/to/video\" controls=\" controls\" ></video></html>"
142+ ;;
143+ " Link" )
144+ echo " [link][1]"
145+ echo
146+ echo " > Quote"
147+ echo
148+ echo " [1]: url"
149+ ;;
150+ esac
151+ elif [[ $JEKYLL_FORMATTING == " textile" ]]; then
152+ case $POST_TYPE in
153+ " Text" )
154+ true
155+ ;;
156+ " Quote" )
157+ echo " bq. Quote"
158+ echo
159+ echo " — Author"
160+ ;;
161+ " Image" )
162+ echo " !url(alt text)"
163+ ;;
164+ " Audio" )
165+ echo " <html><audio src=\" /path/to/audio/file\" controls=\" controls\" ></audio></html>"
166+ ;;
167+ " Video" )
168+ echo " <html><video src=\" /path/to/video\" controls=\" controls\" ></video></html>"
169+ ;;
170+ " Link" )
171+ echo " \" Site\" :url"
172+ echo
173+ echo " bq. Quote"
174+ ;;
175+ esac
215176 fi >> " ${FNAME} "
216177
217178 # Open the file in your favorite editor
218-
219179 " ${JEKYLL_EDITOR:- ${VISUAL:- ${EDITOR:- ${ALTERNATE_EDITOR:- nano} } } } " " ${FNAME} "
180+ ret=" $? "
181+ popd > /dev/null || return " $ret "
182+ return " $ret "
220183}
221184
222185function testsite() {
@@ -225,6 +188,7 @@ function testsite() {
225188 group ' jekyll'
226189
227190 local SITE site
191+ local -i ret
228192 if [[ -z " ${1:- } " ]]; then
229193 echo " Error: no site specified."
230194 echo " The site is the name of the directory your project is in."
@@ -243,8 +207,11 @@ function testsite() {
243207 return 1
244208 fi
245209
246- builtin cd " ${SITE} " || return
210+ pushd " ${SITE} " > /dev/null || return
247211 jekyll --server --auto
212+ ret=" $? "
213+ popd > /dev/null || return " $ret "
214+ return " $ret "
248215}
249216
250217function buildsite() {
@@ -253,6 +220,7 @@ function buildsite() {
253220 group ' jekyll'
254221
255222 local SITE site
223+ local -i ret
256224 if [[ -z " ${1:- } " ]]; then
257225 echo " Error: no site specified."
258226 echo " The site is the name of the directory your project is in."
@@ -271,9 +239,12 @@ function buildsite() {
271239 return 1
272240 fi
273241
274- builtin cd " ${SITE} " || return
242+ pushd " ${SITE} " > /dev/null || return
275243 rm -rf _site
276244 jekyll --no-server
245+ ret=" $? "
246+ popd > /dev/null || return " $ret "
247+ return " $ret "
277248}
278249
279250function deploysite() {
@@ -282,7 +253,7 @@ function deploysite() {
282253 group ' jekyll'
283254
284255 local SITE site REMOTE
285- local -i loc=0
256+ local -i loc=0 ret
286257 if [[ -z " ${1:- } " ]]; then
287258 echo " Error: no site specified."
288259 echo " The site is the name of the directory your project is in."
@@ -292,6 +263,7 @@ function deploysite() {
292263 for site in " ${SITES[@]} " ; do
293264 if [[ " ${site##*/ } " == " $1 " ]]; then
294265 SITE=" $site "
266+ # shellcheck disable=SC2153 # who knows
295267 REMOTE=" ${REMOTES[loc]} "
296268 break
297269 fi
@@ -303,8 +275,11 @@ function deploysite() {
303275 return 1
304276 fi
305277
306- builtin cd " ${SITE} " || return
278+ pushd " ${SITE} " > /dev/null || return
307279 rsync -rz " ${REMOTE?} "
280+ ret=" $? "
281+ popd > /dev/null || return " $ret "
282+ return " $ret "
308283}
309284
310285# Load the Jekyll config
0 commit comments