Turning Midnight Commander into a console browser for GIT

    Instead of a preface ...


    For a long time I wanted to look at the code about how it was done in meld, but only in the console, and I also wanted it to be connected with the GIT file version control system. In general, so that everything is done with 1 button without leaving mc.

    Ydiff

    Once on our channel (or it was on a truck ...) a certain Daniel Borca showed up, made a noise, made a noise and ran away, apparently he didn’t like our bureaucracy, but he left behind some damp patches, for the upcoming release 4.7.0-pre1 midnight commander. One of them contained ydiff. [Ch] and zdiff. [Ch] ... As it turned out, what I wanted to get was long ago implemented in the ancient fork of mc-mp and in the latest version of ru-fork . After a 2-day “sawing”, I connected the file comparison function to the latest version of mc ... Half the battle was done. :)

    View GIT Repository

    Gitfs panel plugin

    The second problem was that I would like to view patches from the GIT repository directly in the midnight commander, directly from the repository directory. And I thought about writing VFS for the midnight commander with the help of which it would be possible to navigate the repository in the right panel. After a few minutes of "picking", the first raw version of gitfs was born, the
    current fully working, but not the final version is presented below:
    #! / bin / sh
     
    LANG = C
    umask 077
     
    gitfs_list ()
    {
        DATE = `date +"% b% d% H:% M "`
        GIT_DIR = "$ 2 / .git"
        user = `whoami`
        git ls-files | while read fname
        do
            echo "-r - r - r-- 1 $ user 0 0 $ DATE` dirname $ fname` / (git) `basename $ fname`"
        done
    }
     
    gitfs_copyout ()
    {
     
        echo -e "$ 2" > "$ 4"
        echo "$ 3" | sed -e s / \ (git \) \ // >> "$ 4"
    }
     
    case "$ 1" in
    list) gitfs_list "$ @" ;;
    copyout) gitfs_copyout "$ @" ;;
    *) exit 1 ;;
    esac
    exit 0
     
     
     

    Gitlogfs panel plugin

    I wanted to not only navigate the repository, but also be able to receive files of any revision. The gitlogfs plugin was written for this .
    #! / bin / sh
     
    LANG = C
     
    changesetfs_list ()
    {
        DATE = `date +"% b% d% H:% M "`
        GIT_DIR = `head -n1 $ 2`" .git "
        fname =` tail -n1 $ 2`
        USER = `whoami`
        git log --abbrev = 7 --pretty =" format:% at% h% an "" $ fname "| while read chset
        do
            TIMESTAMP = `echo $ chset | cut -f1 -d "" `
            DATE =` date -d @ "$ TIMESTAMP" + "% b% d% H:% M" `
            NAME =` echo $ chset | cut -f2 -d "" `" "` basename $ fname`
            echo "-rw-rw-rw- 1 $ USER 0 0 $ DATE $ NAME"
        done
     
    }
     
    changesetfs_copyout ()
    {
        GIT_DIR = `head -n1 $ 2`". git "
        fname = `tail -n1 $ 2`
        chset =` echo "$ 3" | cut -f 1 -d "" `
        filecommit = `git show --raw --pretty = tformat:% h" $ chset "" $ fname "| grep ^: | grep ... | cut -f3 -d" "| cut -f1 -d". " `
        git show" $ filecommit ">" $ 4 "
    }
     
    case" $ 1 "in
      list) changesetfs_list" $ @ "; exit 0 ;;
      copyout) changesetfs_copyout "$ @"; exit 0 ;;
    esac
    exit 1
     


    Connecting gitfs and gitlogfs plugins to the midnight commander

    In order for any panel plugins to connect to mc, just put them in the home directory of the midnight commander ~ / .mc / extfs.d . In order for the gitlogfs plugin to be called when you click on any file that starts with the prefix (git), you need to add a description of this file type in the ~ / .mc / bindings file, something like this:
    regex / ^ \ (git \)
            Open =% cd% p # gitlogfs


    Artwork

    A call to gitfs is made by the cd #gitfs command in the GIT repository directory. Navigation through the repository happens like any file system. Enter gitlogfs by pressing enter on any project file with the prefix (git) . Comparison of 2 arbitrary revisions of the file is performed using the hot key Ctrl-x, Ctrl-y
    Free Image Hosting at FunkyIMG.com


    Free Image Hosting at FunkyIMG.com


    Free Image Hosting at FunkyIMG.com


    Free Image Hosting at FunkyIMG.com

    Also popular now: