This GitHub repository contains bash-completion.el, a script that adds programmable bash completion to Emacs shell-mode. It is based on bash completion and is aware of bash builtins, aliases, and functions. It supports file expansion inside colon-separated variables and after redirections (> or <), escapes special characters when expanding file names, and is configurable through programmable bash completion. It works on remote shells, through TRAMP.
(eval-after-load 'comint
'(progn
(define-key comint-mode-map (kbd "<up>")
#'comint-previous-matching-input-from-input)
(define-key comint-mode-map (kbd "<down>")
#'comint-next-matching-input-from-input)))