Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In Ubuntu 11.04 or 10.04, how can I make the apt-get, apt-cache all in one myapt so that I can simply use one only, like in Fedora?

For example:

myapt search yum   # same as apt-cache search
myapt remove yum   # same as apt-get remove
myapt install yum  # same as apt-get install

Any idea how to do alias for this?

share|improve this question

2 Answers 2

up vote 9 down vote accepted

You could create a script with the following content

#!/bin/bash

command="$1"; shift

case $command in
  add|depends|dotty|dump|dumpavail|gencaches|madison|pkgnames|policy|rdepends|search|show|showpkg|showsrc|stats|unmet|xvcg)
    apt-cache "$command" "$@"
    ;;
  autoclean|autoremove|build-dep|check|clean|dist-upgrade|dselect-upgrade|install|purge|remove|source|update|upgrade)
    apt-get "$command" "$@"
    ;;
esac

Suppose you call it myapt. Then, to still having the benefit of bash completion, you need to add the following lines to ~/.bashrc:

_myapt() {
  _apt_get
  tt=("${COMPREPLY[@]}")
  _apt_cache
  COMPREPLY+=("${tt[@]}")
  return 0
} &&
complete -F _myapt $filenames myapt

Unfortunately $command should precede any options, but seems that bash completion do not works for options that follow command.

share|improve this answer

I'm not sure you can use alias for that, but you could use bash to create a script.
Now I'm no bash scripter, so I wouldn't be able to tell you the exact code for accomplish that, but what you could do is something like (this is just pseudocode, sort of, so don't expect it to work!!!):

var action
var input
get action, input
  if action == search
    then do apt-cache search input
  if action == remove
    then do apt-get remove input
  if action == install
    then do apt-get install input

Keep in mind you can write the script (or even a compiled application) in what ever language you are comfortable with, such as python or ruby for example, it does not have to be bash.

Again, remember my example is just pseudocode.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.