Find a reasonable editor to use by default for the system that the cmd2 application is running on.
173792
def find_editor() -> str:
    """"""
    editor = os.environ.get('EDITOR')
    if not editor:
        if sys.platform[:3] == 'win':
            editor = 'notepad'
        else:
            # Favor command-line editors first so we don't leave the terminal to edit
            for editor in ['vim', 'vi', 'emacs', 'nano', 'pico', 'gedit', 'kate', 'subl', 'geany', 'atom']:
                if which(editor):
                    break
    return editor
616095
def do_edit_settings(fake):
    """"""

    path = resources.user.open('config.ini').name

    click.echo('Legit Settings:\n')

    for (option, _, description) in legit_settings.config_defaults:
        click.echo(columns([crayons.yellow(option), 25], [description, None]))
    click.echo("")  # separate settings info from os output

    if fake:
        click.echo(crayons.red('Faked! >>> edit {}'.format(path)))
    else:
        click.edit(path)
1003107
def type_check_cmd(self, args, range=None):
        """"""
        self.log.debug('type_check_cmd: in')
        self.start_typechecking()
        self.type_check("")
        self.editor.message('typechecking')
884508
private String openTextEditor() throws IOException, InterruptedException {
        String editor = Optional.ofNullable(System.getenv().get("EDITOR")).orElse(EDITOR_DEFAULT);
        File tempFile = new File(StandardSystemProperty.JAVA_IO_TMPDIR.value() + EDITOR_FILE);
        tempFile.createNewFile();

        // Run the editor, pipe input into and out of tty so we can provide the input/output to the editor via Graql
        ProcessBuilder builder = new ProcessBuilder(
                "/bin/bash", "-c",
                editor + " </dev/tty >/dev/tty " + tempFile.getAbsolutePath()
        );

        builder.start().waitFor();
        return String.join("\n", Files.readAllLines(tempFile.toPath()));
    }
1232449
def run(self, default=None):
        
        parent, *sys_args = sys.argv
        self.parent = Path(parent).stem
        cmd_name = default
        if sys_args:
            cmd_name, *sys_args = sys_args

        if cmd_name is None or cmd_name.lstrip("-") in HELP_COMMANDS:
            self.show_help_root()
            return

        command = self.commands.get(cmd_name)
        if command is None:
            self.show_error(f"command `{cmd_name}` not found")
            self.show_help_root()
            return

        args, opts = parse_args(sys_args)
        return command.run(*args, **opts)
589971
def do_edit(self, args):
        """"""
        if 'EDITOR' not in os.environ:
            print('*** $EDITOR not set')
        else:
            path = os.path.join(utils.CONFIG_DIR, 'sql')
            cmd = os.environ['EDITOR']
            try:
                os.system(cmd + ' ' + path)
                if os.path.exists(path):
                    with open(path, 'r') as f:
                        sql = f.read()
                        if sql:
                            self.default(sql)
            finally:
                if os.path.exists(path):
                    os.remove(path)
425396
def prompt(default=None):
    """"""
    editor = 'nano'
    with tempfile.NamedTemporaryFile(mode='r+') as tmpfile:
        if default:
            tmpfile.write(default)
            tmpfile.flush()

        child_pid = os.fork()
        is_child = child_pid == 0

        if is_child:
            os.execvp(editor, [editor, tmpfile.name])
        else:
            os.waitpid(child_pid, 0)
            tmpfile.seek(0)
            return tmpfile.read().strip()
1350861
def edit
      execute_external_command do
        editor = ENV['EDITOR'] || 'vim'
        unless in_zip?
          system %Q[#{editor} "#{current_item.path}"]
        else
          begin
            tmpdir, tmpfile_name = nil
            Zip::File.open(current_zip) do |zip|
              tmpdir = Dir.mktmpdir
              FileUtils.mkdir_p File.join(tmpdir, File.dirname(current_item.name))
              tmpfile_name = File.join(tmpdir, current_item.name)
              File.open(tmpfile_name, 'w') {|f| f.puts zip.file.read(current_item.name)}
              system %Q[#{editor} "#{tmpfile_name}"]
              zip.add(current_item.name, tmpfile_name) { true }
            end
            ls
          ensure
            FileUtils.remove_entry_secure tmpdir if tmpdir
          end
        end
      end
    end
863342
def best(cls):
        
        writer_lookup = dict(
            executable=WindowsExecutableLauncherWriter,
            natural=cls,
        )
        # for compatibility, use the executable launcher by default
        launcher = os.environ.get('SETUPTOOLS_LAUNCHER', 'executable')
        return writer_lookup[launcher]
687375
def normalize_cmd(cmd):
    
    # Use PATH to determine the executable
    exe = normexe(cmd[0])

    # Figure out the shebang from the resulting command
    cmd = parse_filename(exe) + (exe,) + cmd[1:]

    # This could have given us back another bare executable
    exe = normexe(cmd[0])

    return (exe,) + cmd[1:]
1249382
def __complete_cmds(self, text):
        """"""
        return [ name for name in self._cmd_map_visible.keys() if name.startswith(text) ]
276346
def editor(*args, **kwargs):
    '''
    
    '''
    result = click.edit(*args, **kwargs)
    if result is None:
        msg = 'Editor exited without saving, command aborted'
        raise click.ClickException(msg)
    return result
544067
def load_vi_open_in_editor_bindings():
    
    registry = Registry()
    navigation_mode = ViNavigationMode()

    registry.add_binding('v', filter=navigation_mode)(
        get_by_name('edit-and-execute-command'))
    return registry
915290
def current_gvim_edit(op='e', fpath=''):
        
        """
        import utool as ut
        fpath = ut.unexpanduser(ut.truepath(fpath))
        # print('fpath = %r' % (fpath,))
        ut.copy_text_to_clipboard(fpath)
        # print(ut.get_clipboard())
        doscript = [
            ('focus', 'gvim'),
            ('key', 'Escape'),
            ('type2', ';' + op + ' ' + fpath),
            # ('type2', ';' + op + ' '),
            # ('key', 'ctrl+v'),
            ('key', 'KP_Enter'),
        ]
        XCtrl.do(*doscript, verbose=0, sleeptime=.001)
538123
def cmddict(self):
        """"""
        if self._cmddict is None:
            self._cmddict = cmd.getDefaultDict()

        return self._cmddict
1226330
def do_edit(self, arg, arguments):
        

        def _create_file(filename):
            if not os.path.exists(filename):
                file(filename, 'w+').close()

        def _edit(prefix, editors, filename):
            for editor in editors:
                if os.path.exists(editor):
                    _create_file(filename)
                    os.system("{:} {:} {:}".format(prefix, editor, filename))
                    return True
            return False


        filename = arg

        what =  platform.system().lower()
        prefix = ""

        print (what)
        if 'darwin' in what:

            editors = ["/Applications/Aquamacs.app",
                       "/Applications/Emacs.app"]
            prefix = "open -a "

        elif "linux" in what:

            editors = ["/usr/bin/emacs",
                       "/usr/bin/vi",
                       "/usr/bin/vim",
                       "/usr/bin/nano"]

        elif "windows" in what:

            editors = ["emacs",
                       "vi",
                       "vim",
                       "nano",
                       "notepad",
                       "notepad++"]

        else:
            Console.error("Please contact the developers to add an "
                          "editor for your platform")
            return

        if not _edit(prefix, editors, filename):
            Console.error("Could not find working editor in {0}"
                          .format(str(editors)))
689047
def best(cls):
        
        if sys.platform == 'win32' or (os.name == 'java' and os._name == 'nt'):
            return WindowsScriptWriter.best()
        else:
            return cls