📜 ⬆️ ⬇️

Geany and custom scripts

By occupation, you have to edit pieces of the configuration files of Cisco equipment in a text editor. I use the Geany editor (OS Linux), so I will tyunit it and write the script under bash

My tuning is simple, I added a script that adds or removes the “no” command in the selected text


I called the cisco_add_no script and copied it to / usr / bin, just do not forget to give it the right to run:
chmod ug + x / usr / bin / cisco_add_no
')
Scripts for geany can be added to
Edit -> Formatting -> Send Selected to -> Set Custom Commands
There you must specify the name of the script, the selected text is transmitted through the standard stdin

I indicated this way (the 1st one adds “no”, the second one removes it):
cisco_add_no
cisco_add_no unno

#!/bin/bash # # Add or remove "no" from all selected strings in Geany # # Usage: cisco_add_no [w/o arguments] - add "no" to all stdin strings # cisco_add_no unno - remove "no" from all stdin strings # #Get stdin strings my_strings=`xargs -0 echo` #Get count of strings num=`echo "$my_strings" | wc -l` i=0 while [ $i -lt $num ]; do let i+=1 #If we haven't "unno" argument? add "no" to selected strings, otherwise remove "no" if [ "$1" != "unno" ] then printf "no " echo "$my_strings" | head -${i} | tail -1 else echo "$my_strings" | head -${i} | tail -1 | sed -e 's/no //' fi done 


Scripts can be called either from the menu (in the same place where they were added), or via hotkeys Ctrl + 1, Ctrl + 2, etc.

PS Friends, I do not pretend to the uniqueness of the code, I also do not advance in the nomination “the most beautiful code of the year”, I just did as I could. All suggestions for improvement are accepted with pleasure.

Source: https://habr.com/ru/post/130151/


All Articles