Rbbedit
Easily edit server files on your workstation using BBEdit
Install / Use
/learn @cngarrison/RbbeditREADME
rbbedit
Easily edit server files on your workstation using BBEdit.
Important Update: Fix for macOS "Automation Permissions"
A new feature has been added to rbbedit to address the issue of missing Automation permissions when running bbedit
from an SSH session. Users can now request Automation permissions by passing the -P argument to rbbedit. This will
display a dialog in BBEdit, prompting the user to grant the necessary permissions for sshd-keygen-wrapper to control
BBEdit. The permissions only need to be requested once, to update System Settings.
Please see the "Requesting Automation Permissions" section below for detailed instructions on how to use this new feature.
Unleash the Power of BBEdit for Remote File Editing
As a developer or sysadmin, you often find yourself working on remote hosts, connected via SSH. While command-line editors like vi are available on the server, you miss the rich features and intuitive interface of your favorite text editor, BBEdit, on your macOS workstation.
That's where rbbedit comes in. This powerful tool bridges the gap between your local BBEdit installation and remote
file editing needs. With rbbedit, you can seamlessly open and edit files residing on remote hosts using the full
capabilities of BBEdit, right from your macOS workstation.
BBEdit is the leading professional HTML and text editor for macOS, crafted to serve the needs of writers, web authors,
and software developers. It provides an abundance of features for editing, searching, and manipulating prose, source
code, and textual data. By leveraging rbbedit, you can bring the power of BBEdit to your remote file editing workflow.
Imagine the convenience of editing Apache configuration files, server-side JavaScript, or web page content with the
familiar and feature-rich interface of BBEdit. No more struggling with command-line editors or transferring files back
and forth. With rbbedit, you can efficiently edit remote files as if they were local, thanks to BBEdit's built-in SFTP
support.
Whether you're tweaking configuration files, debugging scripts, or updating web content, rbbedit streamlines your
workflow and boosts your productivity. It allows you to leverage the full potential of BBEdit's editing capabilities
while seamlessly integrating with your remote development environment.
It's important to note that rbbedit is designed to open individual files rather than directories. While BBEdit
supports opening directories, rbbedit focuses on providing a smooth experience for editing specific files.
Additionally, rbbedit works with real files on disk and does not support reading from standard input (stdin) in its
current version.
If you frequently find yourself editing files on remote hosts and yearning for the power and convenience of BBEdit,
rbbedit is the tool you've been looking for. Embrace the efficiency and familiarity of BBEdit for your remote file
editing needs with rbbedit.
Usage
Connect to server-host from the BBEdit workstation.
workstation$ ssh server-host
Open filename in BBEdit on workstation, using default copy method (sftp).
server-host$ rbbedit filename
Open filename in BBEdit, connecting to workstation as myuser.
server-host$ rbbedit -u myuser filename
Open filename in BBEdit, using scp method.
server-host$ rbbedit -m scp filename
Open filename in BBEdit, using ExpanDrive with volume named expandrive-volume.
server-host$ rbbedit -x expandrive-volume filename
Request permission for sshd-keygen-wrapper to control BBEdit.
server-host$ rbbedit -P
Send SSH public key from server-host to workstation.
server-host$ rbbedit -u myuser -k send
Get SSH public key from workstation.
server-host$ rbbedit -u myuser -k get
Requirements
Local machine
sshdmust be enabled, and if needed, with firewall and port forwarding configured to allow access to BBEdit workstation- BBEdit command line utilities
- SSH keys for user account (to avoid entering password repeatedly)
Remote machine
shssh- common unix utilities (such as
basename,dirname,curl) - SSH keys for user account (to avoid entering password repeatedly)
Installation
Server Host
- Automatic installation with:
curl -L https://raw.githubusercontent.com/cngarrison/rbbedit/master/install.sh | bash
- Or install manually from GitHub:
wget https://github.com/cngarrison/rbbedit/raw/master/rbbeditchmod 755 rbbedit- Copy
rbbeditsomewhere inPATH cp rbbedit /usr/local/bin/
- Or clone from GitHub:
git clone https://github.com/cngarrison/rbbedit.gitcd rbbedit./install.sh
- Create SSH key pair for user account (unless already done)
ssh-keygen
BBEdit workstation
- Enable SSH (remote login)
- Configure firewall and port forwarding to allow SSH connections
- Copy SSH public key from server(s) to .ssh/authorized_keys (keys can be copied with the
-koption)
Script options
-U username: server-host/SFTP user; specify username to use in hostname argument for SFTP command - will default to $USER-H hostname: server-host/SFTP host; specify hostname or IP address - will default to $HOSTNAME-u username: workstation/SSH user; specify username to use in hostname argument for SSH command-h hostname: workstation/SSH host; specify hostname or IP address, optionally prefix with USER@, eg. myuser@myworkstation.example.com-p port: workstation/SSH port; connect to SSH using port other than 22-m copy-method:sftp | ftp | expan | scp | rsync- method used to copy files between hosts-x expandrive-volume: volume name as configured in drives list of ExpanDrive, implies-m expan-k copy-direction:get | send- direction to copy the SSH key-i identity-file: path to identity file ifssh-copy-idcan't find default public key file-y understood: confirmation that you understand the implication of the 'copy SSH public key' command (not required in current version)-b /path/to/bbedit: path tobbediton the workstation-v: verbose-w: Enable BBEdit wait mode (default)-W: Disable BBEdit wait mode (only sftp, ftp & expan methods)-P: Request Automation permissions forsshd-keygen-wrapperto control BBEdit-R: Copybbedit-restrictedscript to the workstation and display instructions for updatingauthorized_keys-+: self-update-?: help usage
User Defaults
All options specified in the users ~/.rbbedit file will be used as defaults. Options specified on the command line will override user defaults.
The following options can be set in ~/.rbbedit file. These are the script default values.
host_sftp_user=""
host_sftp_host=""
bbedit_ssh_user=""
bbedit_ssh_host=""
bbedit_ssh_port=""
copy_method="sftp" # scp | expan | rsync | sftp | ftp
expan_volume=""
bbedit_prog="/usr/local/bin/bbedit"
bbedit_wait_args=" --wait --resume"
bbedit_wait="$bbedit_wait_args"
local_ssh_copy_id_command="ssh-copy-id"
local_key_identity=""
bbedit_ssh_copy_id_command="/usr/local/bin/ssh-copy-id"
bbedit_key_identity=""
yes_agree=""
verbose=0
Set default for username on BBEdit workstation:
echo 'bbedit_ssh_user="<workstation-username"' >> ~/.rbbedit
Set default copy method to 'ftp':
echo 'copy_method="ftp"' >> ~/.rbbedit
Set path for bbedit:
echo 'bbedit_prog="/usr/bin/bbedit"' >> ~/.rbbedit
Disable the --wait option for bbedit:
echo 'bbedit_wait=""' >> ~/.rbbedit
Set as EDITOR
Use rbbedit as your EDITOR, eg:
export EDITOR="rbbedit -w"
Some programs that use EDITOR don't expect multiple arguments (& editing fails). The solutions is to create a wrapper script and use that for EDITOR.
cat << 'EOF' > wait_rbbedit
#!/bin/sh
rbbedit -w "$@"
EOF
chmod +x wait_rbbedit
mv wait_rbbedit /usr/local/bin/wait_rbbedit
export EDITOR="wait_rbbedit"
Copy Methods
The default copy method is 'sftp'. The 'sftp' method will construct an sftp url and use bbedit to open the file using BBEdit's built-in SFTP functionality.
The 'ftp' copy method is almost identical to the 'sftp' method. The difference is that the home directory will be stripped from the filename, under the assumption that the FTP server is chrooting connections. So a relative path for the filename is used, if the first part of the path matches $HOME. You can disable the relative path behaviour by setting ftp_absolute=1 in your ~/.rbbedit file.
The 'scp' method uses scp to copy each file to edit to the user's TMPDIR, then opens the file using bbedit. Once the file closes (editing is finished) then scp is used to copy file back to the server.
The 'rsync' method is identical to 'scp' except that rsync is used to copy the file each direction.
The 'expan' method will instruct ExpanDrive on the workstation to mount expandrive-volume, and then opens the file using bbedit. The script can't get response indicating whether ExpanDrive has finished mounting the volume successfully, other than checking path exists, so we just sleep for 3 seconds and hope for the best.
All the commands sent from server to the workstation use ssh.
Multiple files can be specified at once. Only one file will opened/edited at a time.
Only files can be specified for scp and rsync methods, while the sftp, ftp and expan methods will also open directories.
Requesting Automation Permissions
If you encounter the following error when running rbbedit from an SSH session:
You must allow the application which is running `bbedit` to send events to the BBEdit application.
Please make appropriate changes in your Security & Privacy system preferences,
or contact your terminal/IDE application's developer fo
