I have text with some leading spaces on all lines. I want to remove the space from the shortest line (if it is easier, this requirement can be changed to the first line), and then remove the same amount of spaces from all the other lines.
eg. I have this text:
var flatten = function(result, next_array) { console.log('current result', result); return result.concat(next_array); }; [1, [2], [3, 4]] .reduce(flatten, []);
And I want to bring to this text:
var flatten = function(result, next_array) { console.log('current result', result); return result.concat(next_array); }; [1, [2], [3, 4]] .reduce(flatten, []);
Basically, I want to move the text until there is one line left without spaces on the left and all the other leading spaces on all other lines remain.
A use case for this is to copy code from the middle of a code section for insertion as an example elsewhere. What I'm doing now is copy the code, paste into vim with paste paste mode , use << until I get the desired result, and copy the buffer. The same can be done in TextMate with Cmd - [ .
I want to do this with a shell script, so that I can, for example, run it with a hotkey to take the contents of the clipboard, remove the desired spaces and paste the result.