A macro for scp the current file

Kuo Kan Liang kkliang at ntu.edu.tw
Sun Mar 4 18:26:45 CET 2007


Hi, nediters,

I have been using nedit for long, but I am new to this mailing list.

I recently wrote a script to scp the current file that I am editing to a
remote server.
I attempted to make the macro as simple as possible, so there are still
somethings to be improved.
For example, I presume that the file I am editing is my own file, that
is, it is somewhere under my own home directroy.

Please give me advices if you have the time to test this macro. Thanks!

Best,
K. K. Liang

############
# Use SCP to send the current file to a remote location
define scp_current_file {
# First try to find the file .nedit_scp_targets.
# If it does not exist, prompt the user to enter the server name
targets_str = read_file( getenv( "HOME" ) "/.nedit_scp_targets" )
sure = 0
if( $read_status == 0 ) {
tstr = string_dialog( "Cannot find ~/.nedit_scp_targets in your
directory.\nEither create one or enter the target name below.",
"Select", "Cancel" )
sure = $string_dialog_button
} else {
tstr = list_dialog( "Choose a server from the list.", targets_str, "OK",
"Cancel" )
sure = $list_dialog_button
}
# Confirm if the remote path is identical to the local path
# or the user wants to input remote path.
if( sure == 1 ) {
new_path = string_dialog( "Change the file path on remote machine?",
"No", "Yes" )
if( $string_dialog_button == 1 ) {
remote_home = replace_in_string( shell_command( "ssh " tstr " pwd", ""
), "\n", "" )
local_home = getenv( "HOME" )
home_file_path = replace_in_string( $file_path, local_home, "" )
remote_path = tstr ":" remote_home home_file_path $file_name
} else {
remote_path = tstr ":" new_path
}
ret_str = shell_command( "scp " $file_path $file_name " " remote_path, "" )
dialog( "Execute command: scp " $file_path $file_name " " remote_path
"\nExit code: " $shell_cmd_status "\nReturn message: " ret_str , "OK" )
}
}
############

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dr. Kuo Kan LIANG (Assistant Research Fellow)
Laboratory of Digital Chemical Kinetics (DiCK)
Thematic Center for Mechanics and Engineering Sciences (TCMES)
Research Center for Applied Sciences (RCAS)
Academia Sinica (AS)
128, Section 2, Academia Road, Nankang, Taipei 115, Taiwan
TEL: +886-2-26539885#859
FAX: +886-2-27826672
Email: kkliang_at_sinica.edu.tw; kkliang_at_ntu.edu.tw
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the Discuss mailing list