Sublime Forum

Bash script - compress and expand IF blocks

#1

Hi everyone,
I’m new to Sublimetext and I’m wondering if I’m doing something wrong.
I’m writing a bash script and I’d like to compress an IF block by pressing the little arrows that the editor shows at the left of the IF. However whenever I click there, it compress random lines under the if block but not the entire block until the fi.

Am I looking for a feature that the editor doesn’t have? If so what are those tiny arrows for?

Thank you!

0 Likes

#2

It’s working fine for me. Do you have an example of code where it isn’t working as expected?

0 Likes

#3

FWIW, https://github.com/sublimehq/Packages/pull/4024 adds tons of improvements for Bash and (adds) ZSH, which includes improved indentation rules and syntax based folding.

0 Likes

#4

Sure, here’s an example, what it compress is just 1 line where there’s an echo:
19

0 Likes

#5

Thank you, I’ll give it a try

0 Likes

#6

For code folding ST often relies on indentation. I suggest properly indenting your script, both for readability and to make code folding work.

0 Likes

#7

Hmm it doesn’t really make a difference on my test for some reason :thinking:

I’ve selected the code, then moved on Edit > Line > Indent, then saw ST indenting the portion of code I’ve selected, tested the compress feature but it still compress only 1 or random lines, instead of compressing the entire IF block

0 Likes

#8

I suggest looking up what indentation should look like. All you’ve done there is make the indentation even more incorrect. See for instance this first google result: https://codehs.gitbooks.io/introcs/content/Programming-with-Karel/how-to-indent-your-code.html

You can also get ST to try to correct your indentation using Edit > Line > Reindent.

0 Likes

#9

FWIW, mentioned PR helps

  1. ensuring consistent indentation while typing by improved indentation rules
  2. enables folding if clauses regardless correct indentation.

It would therefore be good it to find its way into one of the next releases.

With that PR folding works as to be expected…

grafik

becomes:

grafik

0 Likes

#10

Thank you @deathaxe, is there any link that explain how to install the version you shared?

0 Likes

#11

The indentation I’ve tried (manually) didn’t work, so I’ve let ST indent the file automatically (the one you see in my last image) and that was the result. No matter the number of spaces or tabs I use the compress icon only compresses one echo

0 Likes

#12

Here’s a test with the right indentation btw

12

0 Likes

#13

I’m a new user so I wasn’t allowed to show the second picture in a single reply
33

0 Likes

#14

If indentation is correct, folding works as expected for me even with current and recent ST builds, which means both lines being folded as in my last screenshot.

Steps required to install “pre-releases” of bundled ST packages is outlined in readme of https://github.com/sublimehq/Packages.

0 Likes

#15

Thank you!
I’ve performed the commands (but I had to use Sublime Text as folder instead of Sublime Text 3, as I didn’t have that one using the new version). How can I test if the package got installed properly?

0 Likes

#16

Packages folder reached via Main Menu > Preferences > Browse Packages should contain a ShellScript symlink/junction.

0 Likes

#17

Awesome, after a restart it worked :tada:

Thank you both!

0 Likes