Friday, May 3, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 3167  / 3 Years ago, thu, july 22, 2021, 6:04:17

I want to open the output of terminal commands in sublime2.



e.g. when I do $ list , it lists all files/folders in terminal. I want that when I run this command a temporary text file should be created and output is opened in sublime2 editor. I have no intention to save it. I just want to open output in sublime2.



I've seen that you can open in textmate in Mac by piping out the output.



$ls | mate ( I am not sure about the syntax )


More From » gnome-terminal

 Answers
7

You can use a very simple script to do this.



Here is the script:



#! /bin/bash

"$@" > $$.txt
sublime-text $$.txt
rm $$.txt


Save it as sublime.sh (you can use any other name) and make it executable by running:



chmod +x sublime.sh


To use it:



./sublime.sh <command>


Example:



./sublime.sh ls -l


Explanation:




  • Line 1 is the shebang, which just specifies the interpreter.

  • Line 3 runs the command that you passed and saves it in a file named $$.txt. $$ returns the PID of the terminal you're using (feel free to use any other file name).

  • Line 4 opens the file in sublime-text

  • Line 5 deletes the file, since you don't want to save the file permanently.






Update: You can also put it in your ~/.bashrc file to access it easily.




  • Open a terminal.

  • Go to home folder.




cd



  • Open .bashrc file.




gedit .bashrc



  • Copy the following at the end of the file.




function sublime()
{
"$@" > ~/$$.txt
sublime-text ~/$$.txt
rm ~/$$.txt
}



  • Run the following command to refresh:




. .bashrc



  • Done!! Now use it:




sublime ls -l

[#35023] Friday, July 23, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jokaned

Total Points: 315
Total Questions: 116
Total Answers: 119

Location: Somalia
Member since Mon, Feb 27, 2023
1 Year ago
;