Login

Virtualfish Hook

Author:
HubertGrzeskowiak
Posted:
June 11, 2014
Language:
Shell
Version:
Not specified
Tags:
manage virtualenv fish virtualenvwrapper virtualfish
Score:
1 (after 1 ratings)

When you use Virtualfish, the virtualenv wrapper for the fish shell, you can add hooks for whenever the virtualenv is activated. This little snippet sets some important environment variables and adds the manage.py command with autocompletion so that you won't ever need to write "python ./manage.py help" ever again, but only "manage <TAB>".

For this to work you need to source or paste this code in your ~/.config/fish/config.fish

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
function virtualenv_paths --on-event virtualenv_did_activate:YOUR_VIRTUALENV
        # set pythonpath and settings module
        set -gx PYTHONPATH ~/YOUR_PROJECT
        set -gx DJANGO_SETTINGS_MODULE yourproject.settings.settings_dev

        # make manage.py usable from anywhere while the virtualenv is active
        function manage
                python ~/YOUR_PROJECT/manage.py $argv
        end
        
        # set up autocompletions
        function list_django_commands
                manage | python -c "import sys; print '\n'.join([c.replace('    ', '') for c in sys.stdin.read().split('Available subcommands')[1].split('\n') if c.startswith('    ')])"
        end

        complete -x -c manage -a "(list_django_commands)"
end

More like this

  1. Facebook shell by stephenemslie 5 years, 5 months ago
  2. PyCrust Shell by robvdl 7 years, 4 months ago
  3. Quick startup using manage.py shell by dnordberg 7 years, 6 months ago
  4. Control FCGI processes through management by nipuL 6 years, 11 months ago
  5. Autoload Django Models When Using ./manage.py shell by sheats 7 years, 1 month ago

Comments

Please login first before commenting.