summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/cd-after-exit.txt161
1 files changed, 0 insertions, 161 deletions
diff --git a/doc/cd-after-exit.txt b/doc/cd-after-exit.txt
deleted file mode 100644
index ee300518..00000000
--- a/doc/cd-after-exit.txt
+++ /dev/null
@@ -1,161 +0,0 @@
-The "cd-after-exit" Feature
-===========================
-
-Abstract
---------
-
-This document explains the troublesome implementation of the "cd-after-exit"
-feature.
-
-This is written for developers who wonder how it's working.
-
-
-Specification
--------------
-
-When the feature is enabled, ranger will attempt to change the directory of
-the parent shell (from which ranger is run) to the last visited directory
-when ranger is exited.
-
-This task is, by its nature, shell dependent.  As a bash or zsh user,
-I focused on the implementation for those two shells and left the
-addition of support for csh, ksh, and other shells to those who actually use
-those shells.
-
-
-What's the problem?
--------------------
-
-Shells have several limitations, the implementation could not be done easily
-because:
-
-1. It is not possible to use something like system('cd xyz') at the end.
-This command would run in a new shell and wouldn't change the directory
-of the parent shell at all.
-
-2. Using exec('cd xyz') is not possible either, since 'cd' is a command
-which is directly integrated in to the shell and can not be run this way.
-
-
-Redirection of streams
-----------------------
-
-The only way I found is using cd `program` from inside the shell to change
-the directory to whatever `program` prints to the stdout:
-
-    bash$ cd `echo ..`
-
-Since the user interface still has to be printed, we simply redirect it to
-the stderr.  It is not sufficient however to change sys.stdout to sys.stderr,
-since curses seems not to be aware of sys.stdout and continues to print out
-the interface to the actual stdout.
-
-So what I did was swap the stdout and stderr of the whole ranger process on
-the shell command line by using:
-
-    bash$ cd `ranger 3>&1 1>&2 2>&3 3>&-`
-
-Since errors are now printed to the stdout, we have do this in ranger:
-    sys.stderr = sys.__stdout__
-
-And at the end, write the current directory to the stdout, which is now
-reachable via sys.__stderr__ due to the redirections:
-    sys.__stderr__.write(last_visited_directory)
-
-To inform the ranger process about these changes, we add a --cd-after-exit
-switch which:
-    bash$ cd `ranger --cd-after-exit 3>&1 1>&2 2>&3 3>&-`
-
-
-Argument passing
-----------------
-
-This works well enough, but there are two remaining problems:
-
-1. How to pass arguments to ranger?
-
-2. How to memorize that line? Although you can just copy+paste it
-into your bashrc and create an alias, the complexity of the line
-could lead to errors.
-
-Both problems are solved by putting the command in a file:
-
-run.sh:
-    cd "`ranger --cd-after-exit \"$@\" 3>&1 1>&2 2>&3 3>&-`"
-
-The $@ is responsible for argument passing.  By using the source command,
-the file will be evaluated without creating a distinct new shell.
-
-    bash$ source run.sh arg1 ... argN
-
-To add flexibility, replace the name "ranger" in the command to the first
-argument.  Now it requires you to pass the name of the ranger command to
-the script as the first argument:
-
-run.sh:
-    RANGER="$1"
-    shift
-    cd "`$RANGER --cd-after-exit \"$@\" 3>&1 1>&2 2>&3 3>&-`"
-
-
-Put it in a nutshell
---------------------
-
-I didn't want to have 2 files for the main program and wanted just one
-file at /usr/bin/ranger.  So I used this trick to merge both files into one:
-
-    #!/usr/bin/python
-    """":
-    <shell code>
-    """
-    <python code>
-
-If you run this file with python, or simply by typing ranger, the program will
-run normally.  If you, however, run this file by sourcing it into the shell,
-like you did with run.sh, the cd-after-exit mode will be activated.
-
-Now the way of running ranger with the cd-after-exit feature is:
-
-    bash$ source /path/to/ranger.py /path/to/ranger.py
-
-or, if properly installed:
-
-    bash$ source ranger ranger
-
-A convenient way of using this feature is adding this line to your bashrc:
-
-    alias rn='source ranger ranger'
-
-
-Open issues
------------
-
-Unfortunately there is some redundancy: you have to type the path to ranger
-twice.  I know of no way to fix this, because it is not possible to get the
-filename of the file currently being sourced.
-
-Example:
-
-    bash$ echo 'source sourced.sh' > main.sh
-    bash$ echo 'echo $0 $@' > sourced.sh
-    bash$ bash main.sh
-    main.sh
-
-If you find a way to make this print out 'sourced.sh', let me know. :)
-
-Another thing: If Ctrl+C is pressed anywhere in the program, the execution
-of the sourced shell script is stopped and the feature stops working.
-
-This was handled by using a script like that:
-
-    ranger_exec="$1"
-    shift
-    trap "" INT
-    exec 3< <($ranger_exec --cd-after-exit $@ 3>&1 1>&2 2>&3 3>&-)
-    while read ranger_output; do false; done <&3
-    cd "$ranger_output"
-    #...and some clean ups
-
-but that won't work in zsh for some reason, so I took it out again.
-
-Dec 25, 2009
a> 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751