Ranger : do not try to display large files (preview)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I am using Ranger as a file explorer, and by the way it's great...



I have an issue because Ranger can display a preview of the file currently
selected. Which is quite useful but becomes problematic for large files.
Indeed, for large files, it takes a lot of time and ressources to do create a
preview.



My question is : is there a way to set the maximal size for which Ranger won't
try to display a preview ?










share|improve this question



























    up vote
    2
    down vote

    favorite












    I am using Ranger as a file explorer, and by the way it's great...



    I have an issue because Ranger can display a preview of the file currently
    selected. Which is quite useful but becomes problematic for large files.
    Indeed, for large files, it takes a lot of time and ressources to do create a
    preview.



    My question is : is there a way to set the maximal size for which Ranger won't
    try to display a preview ?










    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I am using Ranger as a file explorer, and by the way it's great...



      I have an issue because Ranger can display a preview of the file currently
      selected. Which is quite useful but becomes problematic for large files.
      Indeed, for large files, it takes a lot of time and ressources to do create a
      preview.



      My question is : is there a way to set the maximal size for which Ranger won't
      try to display a preview ?










      share|improve this question















      I am using Ranger as a file explorer, and by the way it's great...



      I have an issue because Ranger can display a preview of the file currently
      selected. Which is quite useful but becomes problematic for large files.
      Indeed, for large files, it takes a lot of time and ressources to do create a
      preview.



      My question is : is there a way to set the maximal size for which Ranger won't
      try to display a preview ?







      ranger






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 19 at 13:42









      Goro

      6,16652762




      6,16652762










      asked Feb 26 '15 at 7:45









      PinkFloyd

      274311




      274311




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          I found the solution, at least for text files, the problem was in the
          highlighting... Ranger was trying to highlight long files... the workaround I
          found is shown in the following excerpt of ~/.config/ranger/scope.sh



          #!/usr/bin/env sh

          path="$1" # Full path of the selected file
          width="$2" # Width of the preview pane (number of fitting characters)
          height="$3" # Height of the preview pane (number of fitting characters)
          maxln=54 # Stop after $maxln lines. Can be used like ls | head -n $maxln

          # Find out something about the file:
          mimetype=$(file --mime-type -Lb "$path")
          extension=$path##*.

          try() output=$(eval '"$@"');
          dump() echo "$output";
          trim() head -n "$maxln";
          hl() highlight --syntax="$extension" --out-format=ansi; test $? = 0 -o $? = 141;

          case "$mimetype" in
          # Syntax highlight for text files:
          text/* | */xml)
          try hl && trim; exit 5; || exit 2;;
          esac
          exit 1


          The idea, it to select only the first lines of the textfile and then call
          highligh only on that portion.






          share|improve this answer





























            up vote
            0
            down vote













            You can include commands, in some parts of your scope.sh, to check for file size.



            First, add new function (paste code above handle_extension() in scope.sh):



            drop_bigsize() 
            # 51200 == 50 MB * 1024
            # change this number for different sizes
            if [[ `du "$FILE_PATH"


            Second, call that function somewhere in scope.sh.

            For example, the code below will prevent from previewing any files with size bigger than 50MB (its the last few lines from scope.sh):



            ...
            MIMETYPE="$( file --dereference --brief --mime-type -- "$FILE_PATH" )"

            ### start of new block ###
            drop_bigsize
            ### end of new block ###

            if [[ "$PV_IMAGE_ENABLED" == 'True' ]]; then
            handle_image "$MIMETYPE"
            fi

            handle_extension
            handle_mime "$MIMETYPE"
            handle_fallback

            exit 1


            To do such stuff with some specific file types, e.g. for some archives, you would need to place the same block of code in different part of your scope.sh:



            ...
            handle_extension() {
            case "$FILE_EXTENSION_LOWER" in
            # Archive
            a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|
            rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
            ### start of new block ###
            drop_bigsize
            ### end of new block ###
            atool --list -- "$FILE_PATH" && exit 5
            bsdtar --list --file "$FILE_PATH" && exit 5
            exit 1;;
            rar)
            # Avoid password prompt by providing empty password
            unrar lt -p- -- "$FILE_PATH" && exit 5
            exit 1;;
            ...





            share|improve this answer






















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f186944%2franger-do-not-try-to-display-large-files-preview%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              5
              down vote



              accepted










              I found the solution, at least for text files, the problem was in the
              highlighting... Ranger was trying to highlight long files... the workaround I
              found is shown in the following excerpt of ~/.config/ranger/scope.sh



              #!/usr/bin/env sh

              path="$1" # Full path of the selected file
              width="$2" # Width of the preview pane (number of fitting characters)
              height="$3" # Height of the preview pane (number of fitting characters)
              maxln=54 # Stop after $maxln lines. Can be used like ls | head -n $maxln

              # Find out something about the file:
              mimetype=$(file --mime-type -Lb "$path")
              extension=$path##*.

              try() output=$(eval '"$@"');
              dump() echo "$output";
              trim() head -n "$maxln";
              hl() highlight --syntax="$extension" --out-format=ansi; test $? = 0 -o $? = 141;

              case "$mimetype" in
              # Syntax highlight for text files:
              text/* | */xml)
              try hl && trim; exit 5; || exit 2;;
              esac
              exit 1


              The idea, it to select only the first lines of the textfile and then call
              highligh only on that portion.






              share|improve this answer


























                up vote
                5
                down vote



                accepted










                I found the solution, at least for text files, the problem was in the
                highlighting... Ranger was trying to highlight long files... the workaround I
                found is shown in the following excerpt of ~/.config/ranger/scope.sh



                #!/usr/bin/env sh

                path="$1" # Full path of the selected file
                width="$2" # Width of the preview pane (number of fitting characters)
                height="$3" # Height of the preview pane (number of fitting characters)
                maxln=54 # Stop after $maxln lines. Can be used like ls | head -n $maxln

                # Find out something about the file:
                mimetype=$(file --mime-type -Lb "$path")
                extension=$path##*.

                try() output=$(eval '"$@"');
                dump() echo "$output";
                trim() head -n "$maxln";
                hl() highlight --syntax="$extension" --out-format=ansi; test $? = 0 -o $? = 141;

                case "$mimetype" in
                # Syntax highlight for text files:
                text/* | */xml)
                try hl && trim; exit 5; || exit 2;;
                esac
                exit 1


                The idea, it to select only the first lines of the textfile and then call
                highligh only on that portion.






                share|improve this answer
























                  up vote
                  5
                  down vote



                  accepted







                  up vote
                  5
                  down vote



                  accepted






                  I found the solution, at least for text files, the problem was in the
                  highlighting... Ranger was trying to highlight long files... the workaround I
                  found is shown in the following excerpt of ~/.config/ranger/scope.sh



                  #!/usr/bin/env sh

                  path="$1" # Full path of the selected file
                  width="$2" # Width of the preview pane (number of fitting characters)
                  height="$3" # Height of the preview pane (number of fitting characters)
                  maxln=54 # Stop after $maxln lines. Can be used like ls | head -n $maxln

                  # Find out something about the file:
                  mimetype=$(file --mime-type -Lb "$path")
                  extension=$path##*.

                  try() output=$(eval '"$@"');
                  dump() echo "$output";
                  trim() head -n "$maxln";
                  hl() highlight --syntax="$extension" --out-format=ansi; test $? = 0 -o $? = 141;

                  case "$mimetype" in
                  # Syntax highlight for text files:
                  text/* | */xml)
                  try hl && trim; exit 5; || exit 2;;
                  esac
                  exit 1


                  The idea, it to select only the first lines of the textfile and then call
                  highligh only on that portion.






                  share|improve this answer














                  I found the solution, at least for text files, the problem was in the
                  highlighting... Ranger was trying to highlight long files... the workaround I
                  found is shown in the following excerpt of ~/.config/ranger/scope.sh



                  #!/usr/bin/env sh

                  path="$1" # Full path of the selected file
                  width="$2" # Width of the preview pane (number of fitting characters)
                  height="$3" # Height of the preview pane (number of fitting characters)
                  maxln=54 # Stop after $maxln lines. Can be used like ls | head -n $maxln

                  # Find out something about the file:
                  mimetype=$(file --mime-type -Lb "$path")
                  extension=$path##*.

                  try() output=$(eval '"$@"');
                  dump() echo "$output";
                  trim() head -n "$maxln";
                  hl() highlight --syntax="$extension" --out-format=ansi; test $? = 0 -o $? = 141;

                  case "$mimetype" in
                  # Syntax highlight for text files:
                  text/* | */xml)
                  try hl && trim; exit 5; || exit 2;;
                  esac
                  exit 1


                  The idea, it to select only the first lines of the textfile and then call
                  highligh only on that portion.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 14 '17 at 7:44

























                  answered Feb 26 '15 at 10:25









                  PinkFloyd

                  274311




                  274311






















                      up vote
                      0
                      down vote













                      You can include commands, in some parts of your scope.sh, to check for file size.



                      First, add new function (paste code above handle_extension() in scope.sh):



                      drop_bigsize() 
                      # 51200 == 50 MB * 1024
                      # change this number for different sizes
                      if [[ `du "$FILE_PATH"


                      Second, call that function somewhere in scope.sh.

                      For example, the code below will prevent from previewing any files with size bigger than 50MB (its the last few lines from scope.sh):



                      ...
                      MIMETYPE="$( file --dereference --brief --mime-type -- "$FILE_PATH" )"

                      ### start of new block ###
                      drop_bigsize
                      ### end of new block ###

                      if [[ "$PV_IMAGE_ENABLED" == 'True' ]]; then
                      handle_image "$MIMETYPE"
                      fi

                      handle_extension
                      handle_mime "$MIMETYPE"
                      handle_fallback

                      exit 1


                      To do such stuff with some specific file types, e.g. for some archives, you would need to place the same block of code in different part of your scope.sh:



                      ...
                      handle_extension() {
                      case "$FILE_EXTENSION_LOWER" in
                      # Archive
                      a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|
                      rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
                      ### start of new block ###
                      drop_bigsize
                      ### end of new block ###
                      atool --list -- "$FILE_PATH" && exit 5
                      bsdtar --list --file "$FILE_PATH" && exit 5
                      exit 1;;
                      rar)
                      # Avoid password prompt by providing empty password
                      unrar lt -p- -- "$FILE_PATH" && exit 5
                      exit 1;;
                      ...





                      share|improve this answer


























                        up vote
                        0
                        down vote













                        You can include commands, in some parts of your scope.sh, to check for file size.



                        First, add new function (paste code above handle_extension() in scope.sh):



                        drop_bigsize() 
                        # 51200 == 50 MB * 1024
                        # change this number for different sizes
                        if [[ `du "$FILE_PATH"


                        Second, call that function somewhere in scope.sh.

                        For example, the code below will prevent from previewing any files with size bigger than 50MB (its the last few lines from scope.sh):



                        ...
                        MIMETYPE="$( file --dereference --brief --mime-type -- "$FILE_PATH" )"

                        ### start of new block ###
                        drop_bigsize
                        ### end of new block ###

                        if [[ "$PV_IMAGE_ENABLED" == 'True' ]]; then
                        handle_image "$MIMETYPE"
                        fi

                        handle_extension
                        handle_mime "$MIMETYPE"
                        handle_fallback

                        exit 1


                        To do such stuff with some specific file types, e.g. for some archives, you would need to place the same block of code in different part of your scope.sh:



                        ...
                        handle_extension() {
                        case "$FILE_EXTENSION_LOWER" in
                        # Archive
                        a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|
                        rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
                        ### start of new block ###
                        drop_bigsize
                        ### end of new block ###
                        atool --list -- "$FILE_PATH" && exit 5
                        bsdtar --list --file "$FILE_PATH" && exit 5
                        exit 1;;
                        rar)
                        # Avoid password prompt by providing empty password
                        unrar lt -p- -- "$FILE_PATH" && exit 5
                        exit 1;;
                        ...





                        share|improve this answer
























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          You can include commands, in some parts of your scope.sh, to check for file size.



                          First, add new function (paste code above handle_extension() in scope.sh):



                          drop_bigsize() 
                          # 51200 == 50 MB * 1024
                          # change this number for different sizes
                          if [[ `du "$FILE_PATH"


                          Second, call that function somewhere in scope.sh.

                          For example, the code below will prevent from previewing any files with size bigger than 50MB (its the last few lines from scope.sh):



                          ...
                          MIMETYPE="$( file --dereference --brief --mime-type -- "$FILE_PATH" )"

                          ### start of new block ###
                          drop_bigsize
                          ### end of new block ###

                          if [[ "$PV_IMAGE_ENABLED" == 'True' ]]; then
                          handle_image "$MIMETYPE"
                          fi

                          handle_extension
                          handle_mime "$MIMETYPE"
                          handle_fallback

                          exit 1


                          To do such stuff with some specific file types, e.g. for some archives, you would need to place the same block of code in different part of your scope.sh:



                          ...
                          handle_extension() {
                          case "$FILE_EXTENSION_LOWER" in
                          # Archive
                          a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|
                          rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
                          ### start of new block ###
                          drop_bigsize
                          ### end of new block ###
                          atool --list -- "$FILE_PATH" && exit 5
                          bsdtar --list --file "$FILE_PATH" && exit 5
                          exit 1;;
                          rar)
                          # Avoid password prompt by providing empty password
                          unrar lt -p- -- "$FILE_PATH" && exit 5
                          exit 1;;
                          ...





                          share|improve this answer














                          You can include commands, in some parts of your scope.sh, to check for file size.



                          First, add new function (paste code above handle_extension() in scope.sh):



                          drop_bigsize() 
                          # 51200 == 50 MB * 1024
                          # change this number for different sizes
                          if [[ `du "$FILE_PATH"


                          Second, call that function somewhere in scope.sh.

                          For example, the code below will prevent from previewing any files with size bigger than 50MB (its the last few lines from scope.sh):



                          ...
                          MIMETYPE="$( file --dereference --brief --mime-type -- "$FILE_PATH" )"

                          ### start of new block ###
                          drop_bigsize
                          ### end of new block ###

                          if [[ "$PV_IMAGE_ENABLED" == 'True' ]]; then
                          handle_image "$MIMETYPE"
                          fi

                          handle_extension
                          handle_mime "$MIMETYPE"
                          handle_fallback

                          exit 1


                          To do such stuff with some specific file types, e.g. for some archives, you would need to place the same block of code in different part of your scope.sh:



                          ...
                          handle_extension() {
                          case "$FILE_EXTENSION_LOWER" in
                          # Archive
                          a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|
                          rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
                          ### start of new block ###
                          drop_bigsize
                          ### end of new block ###
                          atool --list -- "$FILE_PATH" && exit 5
                          bsdtar --list --file "$FILE_PATH" && exit 5
                          exit 1;;
                          rar)
                          # Avoid password prompt by providing empty password
                          unrar lt -p- -- "$FILE_PATH" && exit 5
                          exit 1;;
                          ...






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Sep 19 at 13:39









                          Goro

                          6,16652762




                          6,16652762










                          answered Sep 19 at 13:25









                          banderlog013

                          11




                          11



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f186944%2franger-do-not-try-to-display-large-files-preview%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              How to check contact read email or not when send email to Individual?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?