Shell Bourne SH Customization and Completion

It is possible to complete sh shell commands as in bash example.

Thank you
The FreeBSD /bin/sh supports some basic completion - but better switch to ZSH for best results:

Keep /bin/sh shell on 'toor' account and use ZSH on 'root' account.
 
I use tcsh(1), I like it. Got used to the quirks it has, redirecting works a little different compared to a Bourne compatible shell. But I don't use any complicated redirections on the shell interactively anyway, so it's not a big issue for me. Scripting is done with sh(1), don't use the C shell to write scripts, or you might lose your sanity.
 
Ok tsch instead?
It also works - I just prefer shells in which these work:

Code:
# for I in *; do some-command -opts "${I}"; done
# ls /work | grep REAL | while read I; do some-command -opts "${I}"; done

... and this does not work on fish(1) or csh(1) or tcsh(1) and why use bash(1) if zsh(1) is available with even more completions then bash(1) and fish(1) combined.

Hope that helps.
 
/usr/share/examples/tcsh/complete.tcsh
I noticed a couple of them don't work though. Throw various errors. But it does have some really useful ones.

mayers here's my ~/.cshrc, I've made some changes to the default one you get:
Code:
dice@molly:~ % cat .cshrc

alias h         history 25
alias j         jobs -l
alias la        ls -a
alias lf        ls -FA
alias ll        ls -lA

# A righteous umask
umask 22

set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)

setenv  EDITOR  vi
setenv  PAGER   less
setenv  BLOCKSIZE       K

setenv  CLICOLOR

if ( -x /usr/local/bin/nvim ) then
        alias vi nvim
        setenv EDITOR nvim
endif

if ($?prompt) then
        if ( -f ~/.csh.completions ) then
                source ~/.csh.completions
        endif
        # An interactive shell -- set some stuff up
        switch($TERM)
                case "rxvt":
                case "screen*":
                case "xterm*":
                        set TITLE = "%{\033]0;%n@%m:%~\007%}"
                        breaksw
                default:
                        set TITLE = ""
                        breaksw
        endsw

        set prompt = "${TITLE}%B%n@%m%b:%c03 %# "
        set ellipsis
        unset TITLE
        set promptchars = "%#"

        set filec
        set history = 1000
        set savehist = (1000 merge)
        set autolist = ambiguous
        set autoexpand
        set autorehash
        set mail = (/var/mail/$USER)
        if ( $?tcsh ) then
                bindkey "^W" backward-delete-word
                bindkey -k up history-search-backward
                bindkey -k down history-search-forward
                bindkey "^[[1~" beginning-of-line
                bindkey "^[[4~" end-of-line
                bindkey "^[[3~" delete-char
        endif
endif
 
sh don't support autocompletion. Install other shell...
Traditionally, it hasn't. Since FreeBSD 14.0, it does. However, it may require writing at least 3 letters before auto-completion each time before it works properly.
- command completion
- persistent history support

The following is within my shell configuration file:
Code:
# History complete
bind ^[[A ed-search-prev-history
bind ^[[B ed-search-next-history

The settings for sh also may persist in the terminal, but setting the export ENV may need to be set in .xsession for it to persistently work on the terminal emulator on the desktop. Settings for SH aren't as reliable as other shells.
 
- command completion
- persistent history support

sidetone My point is that completion in sh is just "command/file completion in the PATH". Option completion is not possible (at the moment) in sh.

You can look at the completion capabilities in libedit to verify this (only filenames and executables are completed, not their options).

In the case of "persistent history support" yes, this is old, very old.

If you know any tricks to add options completion to sh, it would be welcome.
 
Sh is still pretty inadequate. For completion to work on the desktop, I have to include the Environment in .xsession. It works on the terminal without needing that. Then, every once in a while, I have to reset it in .xsession, and sometimes restart the sh session.

I didn't fully understand that. However in sh, depending on if I typed a command and arguments in history, later, typing 3 letters, then using the arrow key completes it to what I had under that history. This is a bit more than the old function of using the arrow key, which doesn't limit the results to the letters typed in for auto-completion.

I might switch to mksh for either my user or for root because the environment doesn't persist consistently. Undecided on which account to switch over to mksh. I might leave root as sh.
 
Traditionally, it hasn't. Since FreeBSD 14.0, it does. However, it may require writing at least 3 letters before auto-completion each time before it works properly.

The 3 letter requirement should be documented in the comment in the .shrc

Trying the history feature with ls commands I thought it doesn't work.
 
Is it possible to '-include' some code in .shrc? ie read some configurations from an independent file?
Yes it possible by using the source command .

from the man page sh(1)
. file The commands in the specified file are read and executed by the shell. The return
command may be used to return to the . command's caller. If file contains any ‘/’
characters, it is used as is. Otherwise, the shell searches the PATH for the file. If
it is not found in the PATH, it is sought in the current working directory.

For example you can insert a line at the beginning of your shrc file:
. ~/my_config_file

I don't need to do that for sh because my config file is not that big, but for other shells like zsh or whatever it is useful.
 
Back
Top